Install LAMP (Linux, Apache, MariaDB, PHP) on CentOS 8 / RHEL 8
LAMP stands for Linux, Apache, MySQL and PHP. Most of the websites used LAMP stack and it’s very easy to setup. In this lesson, I’m going to install LAMP on CentOS 8 server. The commands are the same for RHEL 8.
Table of Contents
Step 1 : Install Apache Web Server
On CentOS / RHEL 8, we will use the dnf command to install any package. Before installing Apache, let’s upgrade our operating system by this command:
sudo yum updateNow, let’s install Apache:
sudo dnf install httpdWe need to enable the Apache server to start after reboot:
sudo systemctl enable httpdTo start the Apache server, run this command:
sudo systemctl start httpdIf firewall is enabled on your server, you need to open HTTP (80) port. Let’s open HTTP and HTTPS (443) ports:
# open http
sudo firewall-cmd --zone=public --permanent --add-service=http
# open https
sudo firewall-cmd --zone=public --permanent --add-service=https
# reload firewall
sudo firewall-cmd --reloadWe’ve installed Apache web server on our server. Let’s print a welcome message. Just run this command:
echo "Welcome to CentOS/RHEL 8 Server" > /var/www/html/index.htmlOpen browser and visit the website using the IP address or hostname. Here’s the example http://ip-address/. You’ll see the welcome message.
Step 2 : Install MariaDB Server
We are going to install MariaDB on our server. Run this command to install MariaDB:
sudo dnf install -y mariadb mariadb-serverWe have to enable the MariaDB server to start after each reboot:
sudo systemctl enable mariadbStart the MariaDB server:
sudo systemctl start mariadbLet’s check the status of the MariaDB server:
sudo systemctl status mariadbHere’s the console output:

Let’s secure our MariaDB server. Enter this command:
mariadb-secure-installationYou’ll be asked some questions. The questions and answers are:
1. Enter current password for root (enter for none):
Ans: just press Enter
2. Set root password? [Y/n]
Ans: Y and then set your password.
3. Remove anonymous users? [Y/n]
Ans: Y
4. Disallow root login remotely? [Y/n]
Ans: Y
5. Remove test database and access to it? [Y/n]
Ans: Y
6. Reload privilege tables now? [Y/n]
Ans: YStep 3 : Install Latest PHP
By default, CentOS/RHEL 8 has PHP 7.2 version. We can install by this command:
sudo dnf install -y php php-mysqlndTo install the latest PHP, we have to add two repositories on our server. The first one is the EPEL repository:
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpmThe second one is the Remi repository. Mainly we need this one. Remi repo requires EPEL repo.
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpmSee all available PHP version:
dnf module list phpYou’ll find PHP 7.2, 7.3, and 7.4 versions. Let’s install PHP 7.4:
sudo dnf module install php:remi-7.4Install PHP 7.4 with all necessary modules:
sudo dnf install -y php-cli php-common php-zip php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-pdoNow restart the webserver:
sudo systemctl restart httpdStep 4 : Check PHP Info
Check the PHP version:
# command
php -v
# output
PHP 7.4.0RC4 (cli) (built: Oct 15 2019 11:28:21) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0-dev, Copyright (c) Zend Technologies
with Zend OPcache v7.4.0RC4, Copyright (c), by Zend TechnologiesLet’s test on the live site. Enter this command to create a PHP file and echo phpinfo() function.
echo "<?php phpinfo()?>" > /var/www/html/info.phpNow visit your website by entering the IP or hostname of your server.
http://ip-address/info.phpYou’ll see a page like this:

Md Obydullah
Software Engineer | Ethical Hacker & Cybersecurity...
Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.