Install LAMP Stack on CentOS 8

Last Updated:

This guide describes a step by step tutorial on how to install LAMP stack on CentOS 8.

Installing LAMP Stack on CentOS 8

LAMP is a group of opensource web development softwares; Linux OS, Apache http server, MariaDB/MySQL relational database management systems and PHP web scripting language.

Run system package update.

dnf update

Install CentOS 8 Linux System

In this case, the first component of the LAMP stack is our CentOS 8 Linux system. To install CentOS 8, see our guide on how to install it on VirtualBox by following the link below;

Install CentOS 8 on VirtualBox

Install Apache HTTP Server on CentOS 8

Apache http server can be installed on CentOS 8 as easily as running the command below;

dnf install httpd

Running Apache

Once the installation is done, you can start and enable Apache to run on system reboot by executing;

systemctl enable --now  httpd

To check the status;

systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-10-07 13:59:33 EDT; 42s ago
     Docs: man:httpd.service(8)
 Main PID: 26699 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 11512)
   Memory: 24.8M
   CGroup: /system.slice/httpd.service
           ├─26699 /usr/sbin/httpd -DFOREGROUND
           ├─26700 /usr/sbin/httpd -DFOREGROUND
           ├─26701 /usr/sbin/httpd -DFOREGROUND
           ├─26702 /usr/sbin/httpd -DFOREGROUND
           └─26703 /usr/sbin/httpd -DFOREGROUND

To verify if it is enabled to run on boot, run the command below. The output should enabled;

systemctl is-enabled httpd

Allow Apache Through the FirewallD

To enable external access to Apache web server, you need to allow web traffic on FirewallD. If you are serving just HTTP traffic, just open port 80/tcp otherwise, open port 443/tcp

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload

Testing Apache

To confirm that Apache is ready to server HTTP content, simply open your browser and enter the server IP address as http://Server.IP. You should land on Apache HTTP server test page.

Install LAMP Stack on CentOS 8

Install MariaDB Database Server on CentOS 8

Install MariaDB on CentOS 8 with the command;

dnf install mariadb-server

This installs MariaDB 10.3.

mysql -V
mysql  Ver 15.1 Distrib 10.3.11-MariaDB, for Linux (x86_64) using readline 5.1

Want to use MariaDB 10.4 instead, follow the link below to install MariaDB 10.4 on CentOS 8.

Install MariaDB 10.4 on CentOS 8

You can also use MySQL 8 instead;

Install MySQL 8 on CentOS 8

Once you have installed MariaDB server, start and enable it to run on system boot.

systemctl enable --now  mariadb

Next, run the security script to disable remote root login, remove test databases, remove anonymous user accounts.


You can login to your MariaDB server and create your databases.

Install PHP on CentOS 8

Install PHP and MySQL PHP module on CentOS 8 by running the command;

dnf install php php-mysqlnd

The command above installs PHP 7.2. To use PHP 7.3 instead, you need to install remi repos.

dnf install
dnf install

Reset PHP 7.2 module;

dnf module reset php:7.2

Enable PHP 7.3 remi repository.

dnf module enable php:remi-7.3

Install PHP 7.3 on CentOS 8

dnf install php php-mysqlnd
 Package                           Arch                    Version                                                 Repository                     Size
 php                               x86_64                  7.3.12-1.el8.remi                                       remi-modular                  3.0 M
 php-mysqlnd                       x86_64                  7.3.12-1.el8.remi                                       remi-modular                  252 k

Want to use PHP 7.4? See the link below on how to install PHP 7.4 on CentOS 8.

Install PHP 7.4 on CentOS 8

If you need other PHP extensions for your web applications, simply install by running;

dnf install php-EXTENSION

Replacing EXTENSION with your respective PHP module.

Testing PHP on CentOS 8

You can test PHP to confirm that is working as required as well check the version and installed modules using the simple PHP info script.

vim /var/www/html/test.php

Save the file and exit the file.

Restart Apache

systemctl restart httpd

Navigate to the browser and enter the address, http://<server-IP>/test.php

PHP on CentOS 8

There you go, Your LAMP stack is installed on CentOS 8 and is ready for your web development tasks.

Be sure to remove PHP test page.

rm -rf /var/www/html/test.php

Related Tutorials

Install LAMP Stack on Fedora 30

How To Install LAMP (Linux, Apache, MySQL, PHP) Stack on Fedora 28/29

Install LAMP Stack with MariaDB 10 on Debian 10 Buster

Install LAMP Stack on Debian 9


We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
I am the Co-founder of, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment