The LAMP Stack stands for Linux, Apache, MySQL, and PHP. Together they create server software for delivering high-performance web applications. You can deploy any web application written in PHP programming language using MySQL as the database server.

Advertisement

The Apache web server is responsible for listening to client requests and responding to the application data. It uses a PHP module to compile PHP applications and generate HTML for web browsers.

This tutorial helps you to install Apache, MySQL, and PHP on the Fedora system.

Prerequisites

Login to your Fedora system and open a terminal. Now upgrade the current packages to the latest version by running the following command.

sudo dnf update

Step 1 – Apache Installation

Apache is the most popular web server widely used by Linux systems. Run the below command to install the Apache server using the DNF tool.

sudo dnf install httpd

Now enable the Apache service and start it using the systemctl command

sudo systemctl enable httpd.service
sudo systemctl start httpd.service

Then verify httpd service is running properly:

sudo systemctl status httpd.service

Step 2 – MariaDB Installation

MariaDB is a drop-in replacement of the MySQL database server built by the original MySQL developers. You can install MariaDB from official yum repositories by running the following command.

sudo dnf install mariadb-server

Don’t like MariaDB? Use this tutorial to install MySQL on Fedora.

Now enable the MariaDB service and start it

sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service

After completing the installation process, run the secure installation script to secure the MariaDB instance.

sudo mysql_secure_installation

Follow the onscreen instructions. The default password is none. Change your root account password and Press Y for all other operations to apply improved security.

  • Enter current password for root (enter for none): [ PRESS ENTER ]
  • Set root password? [Y/n] y
  • New password: [ ENTER PASSWORD HERE ]
  • Re-enter new password: [ RE-ENTER PASSWORD HERE ]
  • Remove anonymous users? [Y/n] y
  • Disallow root login remotely? [Y/n] y
  • Remove test database and access to it? [Y/n] y
  • Reload privilege tables now? [Y/n] y

Now check the MariaDB service status.

sudo systemctl status mariadb

Step 3 – PHP Installation

PHP is the most popular programming language. It’s widely used for website development. You can simply run below command to install the latest available PHP version using DNF.

sudo dnf install php php-common

You may also require some modules as per your requirements. Install the required PHP modules on your system.

sudo dnf install php-mysqlnd php-xml php-json php-gd php-mbstring

Verify the current active PHP version on your system

php -v

PHP 7.2.17 (cli) (built:  Apr 18 2019 14:12:38) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Step 4 – Add Firewall Rules

As per our reader’s comment. I am including the below steps to enable firewall access for HTTP(80) and HTTPS(443). To understand about FirewallD read our next tutorial.

sudo firewall-cmd –permanent –add-service=http
sudo firewall-cmd –permanent –add-service=https

Then reload the firewall daemon to apply the above changes.

sudo systemctl reload firewalld

Step 5 – Test Setup

To test the installation, create a phpinfo() function file under the default document root directory. The Apache default document root on Fedora is /var/www/html.

sudo vim /var/www/html/phpinfo.php

Add the following content:

Now access the phpinfo.php file using your system IP address in a web browser. To find your system IP use the command

nmcli -p device show

Access the below URL with the IP found in the above command:

Open in browser
  http://192.168.1.100/phpinfo.php

Conclusion

This tutorial helped you to set up a high-performance web server with LAMP Stack (Linux, Apache, MySQL, and PHP). Next, you may like to install phpMyAdmin on your system to manage database using web interface.

Share.

19 Comments

  1. Hellow. I’m trying to install joomla but there are some problems with /var/www/html folder permissions and it ask fpt account during installation process. Is it correct to leave as root user permissions or must be apache user for this folder? In any case it does not work on fedora 34
    Thanks

  2. Hello nice tutorial, just need add
    systemctl start php-fpm
    and later when install php and php-common just restart http using
    systemctl restart httpd
    nice job and nice web congratulations!

  3. Fizzle_Fuze on

    Apache isn’t handling PHP pages properly for me. It offers them for download instead of executing them. From what I’ve read on older versions, it needs a shared object loaded in httpd.conf, but I cannot find that .so on my system.

  4. Some of the commands were slightly different on my version of Fedora, dunno why I’m new to Fedora.

    These are what I had to type in for the firewall settings:
    firewall-cmd –permanent –add-service=http
    firewall-cmd –permanent –add-service=https

    and then I had to restart apache like Lucas abouve

    sudo systemctl restart httpd

    • In Fedora 33 I had to use
      sudo firewall-cmd –add-service=http –add-service=https ––permanent

      sudo systemctl stop firewalld
      sudo systemctl start firewalld

  5. I followed all these steps but I am stuck in the final tep where the page is taking too long to load and is not displaying the phpinfo page. I get a connection timed out , 192.168.1.100 taking too long to respond message.

    • Your ip address might not be 192.168.1.100
      Type “nmcli -p device show” to get this information, it can be something like 127.0.0.1

  6. firewall-cmd –permanent –add-service=http
    firewall-cmd –permanent –add-service=https
    systemctl reload firewalld

    those three commands save my day… especially the last one … reloading the firewall daemon … *doh*

    • You’re using the incorrect syntax

      firewall-cmd –zone=public –add-service=http –permanent
      firewall-cmd –zone=public –add-service=https –permanent
      systemctl reload firewalld

  7. Lucas Borges on

    Great tutorial!

    In my machine when I went to “http://192.168.1.100/phpinfo.php” i saw the php source code.
    To solve the problem I restarted the apache running this command on therminal.

    $ sudo systemctl restart httpd

    Apart from this, everything was ok.

Leave A Reply