LAMP is an acronym of Linux, Apache, MySQL, and PHP. It is a free and open-source stack used by developers and website administrators to test and host their Web applications. It comes up with 4 components which are Apache (used for hosting a website), MySQL or MariaDB, and PHP – a popular scripting language used to create dynamic web pages. MariaDB or MYSQL are used to store and manage the data.

In this tutorial, we will learn how to install a LAMP Server on CentOS 8. So, let’s get started.

CentOS LAMP Installation

Before installation, keep your Systems Packages repository updated. For this, open up the terminal and use the following command:

# sudo dnf update

Update package lists

Installing Apache Web Server on CentOS8

After updating the system packages, the next step is to install the Apache Web Server and its tools, for this run the following command:

# sudo dnf install –y httpd httpd-tools

Install Apache web server with dnf package manager

Once the installation is completed, enable and start the Apache service by running the following command:

# systemctl start httpd
# systemctl enable httpd

To verify the service is running, run the following command:

# systemctl status httpd

Apache is up and running

As you can see that see Apache web service is running.

Configure CentOS Firewall

After installing Apache, update the firewall rules to allow requests for this use the following command:

# sudo firewall-cmd –add-service=http/tcp –permanent
# sudo firewall-cmd –add-service-https/tcp –permanent
# sudo firewall-cmd –reload

Additionally, you can open up a web browser and test your Web Services by typing IP address or localhost as shown below.

Apache test page

Now we have the Web server installed and running.

Installing MariaDB on CentOS 8

The next step is to install the Maria DB to store data and manage data for the website, for this use the following command:

# sudo dnf install –y mariadb-server mariadb

Install MariaDB

Once the installation is completed, enable and start the Maria DB service by running the following command:

# systemctl enable mariadb
# systemctl start mariadb

To verify the service is running, use the following command:

# systemctl status mariadb

MariaDB Status

As you can see above that MariaDB is running.

To improve the security of the database, it’s recommended to run a security script that comes up with the MariaDB. It will remove the insecure default settings and lock the access of your database. To secure MariaDB by running the following command:

# mysql_secure_installation

It will prompt you to enter the root password or set it up, therefore, answer “Y” for every subsequent prompt.

Secure MariaDB

Installing PHP on CentOS 8

The last component in the LAMP stack is PHP, I already mentioned that PHP is used to create a dynamic web page, to install PHP using the following command:

# sudo dnf install –y php php-mysqlnd

Install PHP

Testing the PHP

To test the PHP create a page under /var/www/html/ directory (default directory). Insert the code as shown below:

Test PHP file - phpinfo

<?php

phpinfo (); // it will print the PHP Information that we have installed

?>

Need to instruct SELinux to execute PHP code, for this use the following command:

# setsebool –P httpd_execmem 1

Finally restart the httpd service.

# systemctl restart httpd

Now open the web browser and type the IP address of your server on the search bar. You will get the output like shown below:

http://<ip-address>/info.php

PHP tested successfully

We have PHP version 7.2.11 is installed and we can see PHP complete information on the web page.

Conclusion

In this tutorial, we learned how to set up LAMP Server with its component Apache, MariaDB, and PHP on CentOS 8. We also see how to handle PHP requests. I hope this tutorial will help you to set up a LAMP Server.

How to install the LAMP Stack on CentOS 8
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn