Stack Engineer

LAMP Setup on CentOS (Linux, Apache, MariaDB, and PHP)

A LAMP stack is an acronym for Linux (CentOS), Apache, MySql (MariaDB), and PHP. This guide assumes you have CentOS already installed and you have connected to the server as a non-root user.

Step 1 - Install the Apache Web Server

Install Apache through the CentOS package manager, yum. We'll then start the Apache service as well as enable it to automatically start when the system boots.

sudo yum install httpd
sudo systemctl enable httpd
sudo systemctl start httpd

Step 2 - Modify Firewall Settings

Configure the firewall to allow connections to http and https:

sudo firewall-cmd --permanent --zone=public --add-service=http 
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Step 3 - Install MariaDB

Install MariaDB through the CentOS package manager, yum. We'll then start the MariaDB service as well as enable it to automatically start when the system boots. Lastly, run the configuration script to modify some of the default settings.

sudo yum install mariadb mariadb-server
sudo systemctl enable mariadb
sudo systemctl start mariadb
sudo mysql_secure_installation

Step 4 - Install PHP

Install PHP through the CentOS package manager, yum. We'll then need to restart the Apache service so that it can load the PHP module.

sudo yum install php php-mysql
sudo systemctl restart httpd