Categories: CentOSLinuxShell

How to install the LAMP Stack on CentOS 8

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

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

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

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.

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

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

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.

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

Testing the PHP

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

<?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

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.

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

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago