LAMP stands for Linux, Apache, MySQL, and PHP. It is a free open source stack used by developers and website administrators to test and host their web applications. It includes 4 components: Apache (used to host a website), MySQL or MariaDB, and PHP is a popular scripting language used to create dynamic web pages. MariaDB or MYSQL are used to store and manage data.
In this tutorial, we will learn how to install a LAMP server on CentOS 8. So, let’s get started.
Installing CentOS LAMP
Please update the system packages repository before installing. To do this, open a terminal and use the following command:
# sudo dnf update
Installing Apache web server on CentOS8
After updating the system packages, the next step is to install the Apache web server and its tools, to do this, run the following command:
# sudo dnf install –y httpd httpd-tools
Once the installation is complete, enable and start the Apache service by running the following command:
# systemctl start httpd # systemctl enable httpd
To verify that the service is running, run the following command:
# systemctl status httpd
As you can see, the Apache web service is running.
Configure CentOS Firewall
After Apache is installed, update your firewall rules to allow requests for this using the following command:
# sudo firewall-cmd –add-service=http/tcp –permanent # sudo firewall-cmd –add-service-https/tcp –permanent # sudo firewall-cmd –reload
Alternatively, you can open a web browser and test your web services by typing IP address or localhost as shown below.
We now have a web server installed and running.
Installing MariaDB on CentOS 8
The next step is to install Maria DB to store and manage data for the website, to do this, use the following command:
# sudo dnf install –y mariadb-server mariadb
Once the installation is complete, enable and start the Maria DB service by running the following command:
# systemctl enable mariadb # systemctl start mariadb
To verify that the service is running, use the following command:
# systemctl status mariadb
As you can see above, MariaDB is working.
To improve the security of your database, it is recommended that you run the security script that comes with MariaDB. It will remove unsafe defaults and block access to your database. Secure MariaDB by running the following command:
You will be prompted for a root password or set one, so answer “Y” for each subsequent request.
Install 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 with the following command:
# sudo dnf install –y php php-mysqlnd
To test PHP, create a page under / var / www / html / directory (default directory). Paste the code as shown below:
<?php phpinfo (); // it will print the PHP Information that we have installed ?>
You need to tell SELinux to execute PHP code by using the following command:
# setsebool –P httpd_execmem 1
Finally, restart the httpd service.
# systemctl restart httpd
Now open your web browser and enter your server’s IP address in the search bar. You will get the result as shown below:
We have PHP 7.2.11 installed and we can see the complete PHP information on the web page.
In this tutorial, we learned how to set up a LAMP server with its Apache, MariaDB and PHP components on CentOS 8. We will also see how to handle PHP requests. I hope this tutorial helps you set up a LAMP server.
How to install LAMP stack on CentOS 8