The LAMP server is one of the most commonly used sets of open-source applications for building web applications. LAMP is a stable and powerful server structure and, at the same time, is very easy to use and set up. LAMP is an acronym for the four components comprising it: Linux, Apache, MySql, and Php. A similar counterpart for Windows and MacOS is also there, namely, WAMP and MAMP.

Prerequisites:

Before proceeding to install the LAMP server in Fedora OS, make sure that you fulfill the following prerequisites:

  1. Have Fedora OS installed on your system. In this article, we are using Fedora 32 OS.
  2. Have root privileges access to the system you are working on.
  3. Have good Internet connectivity for downloading the various packages.

This guide shows you how to install the three components of the LAMP server. Later, you will learn how to make a basic LAMP application to check whether the installation is working as expected.

The following sections show the installation process for installing the LAMP server in Fedora OS:

Installing Apache

To install the Apache, or httpd, web server, run the following command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/image1.png" data-lazy- height="621" src="data:image/svg xml,” width=”1276″>

Next, enable the Apache service to automatically start at next system bootup:

# systemctl enable httpd.service

Now, start the service and check the status with the following commands:

# systemctl start httpd

# systemctl status httpd

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/image8.png" data-lazy- height="498" src="data:image/svg xml,” width=”1418″>

Allow the HTTP and HTTPS services from the firewall. This is necessary if your firewall is blocking access to these services:

# firewall-cmd –permanent –add-service=http

# firewall-cmd –permanent –add-service=https

# firewall-cmd –reload

The process of installing Apache is now finished. Next, we will continue with the installation of the MariaDB database.

Installing MariaDB

MariaDB is a fork of the original MySQL database.

To install the MariaDB database in Fedora, issue the following command:

# dnf install mariadb-server -y

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/image3.png" data-lazy- height="870" src="data:image/svg xml,” width=”1817″>

Once the installation is completed, we will enable and start the mariaDB service, as we did for the Apache server:

# systemctl enable mariadb

# systemctl start mariadb

# systemctl status mariadb

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/image2.png" data-lazy- height="873" src="data:image/svg xml,” width=”1817″>

To finish configuring and securing the MariaDB server, we need to tweak certain settings. Run the command below to begin the secure installation of the MariaDB server:

#  mysql_secure_installation

When you run the above command, a set of questions will appear on the screen, such as:

1. Enter current password for root (enter for none): [press Enter]

Here, simply press Enter, as there is no default password the first time that you configure MariaDB.

2. Switch to unix_socket authentication [Y/n] n

From MariaDB 10.4, a new authentication method has been added based on unix_scoket. In this guide, we will go through with the conventional MariaDB password. Continue by typing N/n.

3. Change the root password? [Y/n] n

Note that we are already the root user when installing MariaDB 10.4, so we automatically have password-less, root-like access. Continue by typing N/n.

4. Remove anonymous users? [Y/n] y

Here, we will remove the anonymous user. The anonymous user allows anyone to log in to the database without an account. Removing the anonymous user is necessary for a production environment, as this account is only meant for testing purposes. Continue by typing Y/y.

5. Disallow root login remotely? [Y/n] y

Next, deny access for root login from remote address to improve security. Continue by typing Y/y.

6. Remove test database and access to it? [Y/n] y

The test database is a default database that can be accessed by anyone. Like the anonymous user, the test database is only meant for testing purposes and should be removed before moving to a production environment. Type Y/y here, as well.

7. Reload privilege tables now? [Y/n] y

Press Y/y to apply all the above changes immediately.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/image4.png" data-lazy- height="873" src="data:image/svg xml,” width=”1817″>

Now, the installation and configuration of MariaDB is complete. We will now move on to install PHP.

Installing PHP

PHP is one of the most widely used scripting languages for application development. To install PHP in Fedora 32 OS, we will run the following command:

# dnf install php php-common

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/image6.png" data-lazy- height="873" src="data:image/svg xml,” width=”1817″>

Development with PHP will likely require the installation of several application-specific PHP modules, as shown below:

# dnf install php-mysqlnd php-gd php-mbstring

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/image5.png" data-lazy- height="873" src="data:image/svg xml,” width=”1817″>

Some of these modules could already be installed with PHP; in our case, php-mbstring was installed alongside PHP.

A note about these modules:

php-mysqlnd – MySQL Native Driver Plugin, or msqlnd, is required by PHP for working with the MariaDB/MySQL database.

php-gd – Required by PHP for working with and handling various image file (GIF, PNG, JPEG, etc.) operations.

php-mbstring – This module provides PHP with multibyte string handling capability.

Testing the LAMP Server Configuration

After installing PHP, we are now all set to test our configuration. We will create a test project to check whether all the components of our LAMP setup are working properly.

Follow the steps below to do so:

Log in to the MariaDB database, as shown below:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/image7.png" data-lazy- height="876" src="data:image/svg xml,” width=”1817″>

For MariaDB 10.4, we do not need to specify the password to log in as a system-wide root user.

As we have denied the remote access for the root login in MariaDB while installing, we need to create a new user for remote access. In MariaDB, run the following command to create a new user:

CREATE USER ‘myuser’@‘localhost’ IDENTIFIED BY ‘123’;

GRANT ALL ON *.* TO ‘myuser’@‘localhost’;

flush privileges;

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/image10.png" data-lazy- height="876" src="data:image/svg xml,” width=”1817″>

Return to the Apache root document directory and create a file with any name; for example, we will use “test.php.”

Put the following code inside the new file and save it:

<html>

   <head>

     <title>LAMP Application</title>

   </head>

   <body>

      <?php

     $stmt = new mysqli(“localhost”,”myuser”,”123)

     if($stmt->connect_error) {

        die(‘Error in Connection ->’.$stmt->connect_error);

      }

      echo ‘Connection successful: You are all set to go.’;

      ?>

   </body>

</html>

Open a web browser and navigate to the following address:

http://localhost/test.php

or

http://”Apache_System_IP ”/test.php

If you have correctly followed the steps provided in the procedure above, you should now be able to see the “Connection successful” message, as shown below:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/image9.png" data-lazy- height="876" src="data:image/svg xml,” width=”1817″>

Conclusion

Congratulations! You have successfully built a LAMP environment and deployed a basic working LAMP application. In this guide, you learned how to install a LAMP server in Fedora OS, as well as the method for deploying a basic application using the LAMP server. If you found this guide useful, then please share it with others.

About the author

<img alt="Ali Imran Nagori" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/IMG_20201123_090644_2-150×150.jpg" height="112" src="data:image/svg xml,” width=”112″>

Ali Imran Nagori

Ali imran is a technical writer and Linux enthusiast who loves to write about Linux system administration and related technologies. You can connect with him on LinkedIn


.