Install LAMP stack on CentOS 8

Install LAMP stack on CentOS 8

In this post, you’ll install the LAMP stack on CentOS 8 server. Although MySQL is available from the default repositories in CentOS 8, this guide will walk through the process of setting up a LAMP stack with MariaDB as the database management system.

Point1: To follow this guide, you’ll need access to a CentOS 8 server as a root user.

Point2: in this tutorial, we use the DNF command for installing packages. DNF Command is pre-installed in CentOS 8. If not installed, you can follow the DNF command on CentOS 8 tutorial.


Install LAMP stack on CentOS 8

Step A: Install Apache on Centos 8

Install the httpd package with:

dnf install httpd
Recommended Article: Tutorial WordPress installation with Nginx in Ubuntu 20.04


After the installation is finished, run the following command to enable and start the server:

systemctl start httpd  systemctl enable httpd

If firewalld is active, you’ll need to run the following command to allow external access on port 80:

firewall-cmd --permanent --add-service=http  firewall-cmd --reload

you can test if the server is up and running by accessing your server’s public IP address or domain name from your web browser. You’ll see a page like this:

apache on centos 8

Step B: Install MariaDB on  Centos 8

We’ll now install MariaDB, a community-developed fork of the original MySQL server by Oracle. To install this, run:

dnf install mariadb-server

After installation, enable and start the MariaDB server with this command:

systemctl start mariadb  systemctl enable mariadb
Recommended Article: Learn how to setup VPS in Windows 10 using XAMPP


For more security of your database you have to run following command and follow the instruction:


The first prompt will ask you to enter the current database root password and because you don’t have any password yet, just press Enter key to continue steps.

Now you have to type a new password for root and confirmation. after that you can skip all steps with press Y and Enter.

Step C: Install PHP on Centos 8

To install the PHP and PHP-mysqlnd following the command:

dnf install php php-mysqlnd

Now, you have to restart Apache after installation complete.

systemctl restart httpd

Great! LAMP stack installed on your CentOS 8 VPS or dedicated Server and now for testing LAMP stack, you can following steps.


Step D: Test PHP with Apache on CentOS 8

We’ll now create a test PHP page to make sure the Web server works as expected.

vi /var/www/html/info.php

Copy and paste below code on the file open

<?php  phpinfo();

Now, press Esc and type :wq for saving the file.

To test your web server can correctly display content generated by a PHP, go to your browser and access your server hostname or IP address with /info.php. Like :


IF all configuration is OK, you see a page like this:

php info Lamp stack centos 8

In install LAMP stack on CentOS 8 tutorial you learn how to install Apache, MariaDB and PHP on your server.


Also, read

Install WordPress with LEMP on Ubuntu 18.04

How to install LEMP stack on Ubuntu 20.04

How to install LEMP on CentOS 8


We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave Your Comment

Your email address will not be published.

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way


7 days a week, 24 hours a day