This guide demonstrates how to install LAMP Stack on CentOS 8, we have explained how to Install MySQL as well as MariaDB an alternative for MySQL.

1. Installing Apache Web Server

Apache web server is one of the most popular web servers in the world, there active community and detailed documentation over server eventually makes it a great choice for hosting a website.

Install Apache using ( Yellowdog Updater, Modified ) YUM :

The sudo (Super User DO) command allows you to run programs with the security privileges.

sudo yum update
sudo yum install httpd -y

Once the installation is completed, enable and start the Apache service.

sudo systemctl enable httpd
sudo systemctl start httpd

Configure Firewall

Enable Firewalld

systemctl enable firewalld

Start Firewalld

systemctl start firewalld

Check the Status of Firewalld

systemctl status firewalld

If your server is protected by the firewall and you haven’t opened the HTTP and HTTPS ports. Enable them with the following command.

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

To verify that the change was applied, you can run:

sudo firewall-cmd --permanent --list-all

You’ll see output like this:

  target: default
  icmp-block-inversion: no
  services: cockpit dhcpv6-client http https ssh
  masquerade: no
  rich rules: 

You’ll need to reload the firewall configuration so the changes take effect:

sudo firewall-cmd --reload

Now you can verify Apache installation. Every process in Apache is managed with the systemctl command. Verify the installation of Apache with the following command.

sudo systemctl status httpd
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset>
   Active: active (running) since Mon 2020-09-07 13:09:19 CST; 8min ago
     Docs: man:httpd.service(8)
 Main PID: 73176 (httpd)
   Status: "Total requests: 6; Idle/Busy workers 100/0;Requests/sec: 0.0116; Byt>
    Tasks: 213 (limit: 5045)
   Memory: 19.6M
   CGroup: /system.slice/httpd.service
           ├─73176 /usr/sbin/httpd -DFOREGROUND
           ├─73177 /usr/sbin/httpd -DFOREGROUND
           ├─73178 /usr/sbin/httpd -DFOREGROUND
           ├─73179 /usr/sbin/httpd -DFOREGROUND
           └─73180 /usr/sbin/httpd -DFOREGROUND

Sep 07 13:09:19 iZa2dc2w6sz7gbkh2kc8exZ systemd[1]: Starting The Apache HTTP Ser>
Sep 07 13:09:19 iZa2dc2w6sz7gbkh2kc8exZ httpd[73176]: AH00558: httpd: Could not >
Sep 07 13:09:19 iZa2dc2w6sz7gbkh2kc8exZ systemd[1]: Started The Apache HTTP Serv>
Sep 07 13:09:19 iZa2dc2w6sz7gbkh2kc8exZ httpd[73176]: Server configured, listeni>

You can check which IP address is accessible, by running the following command:

curl -4

Type the IP address that you receive in your web browser and it will take you to Apache’s default landing page:

2. Install MySQL/MariaDB Database

The third layer of the LAMP stack is MySQL or MariaDB. Both are open-source database management systems used for storing and managing data on your website.

To Install MySQL:

sudo yum install mysql-server -y

To Install MariaDB:

sudo yum install mariadb-server -y
If command sudo systemctl enable mysqld.service leads to a prompt ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' then restart DB as follow's:

For MySQL:

service mysqld start

For MariaDB:

sudo systemctl start mariadb

After completing the installation, enable the MySQL service to auto-start on the system start. Also start service manually for the first time.

sudo systemctl enable mysqld.service
sudo systemctl start mysqld.service

Then check the service current status using the following command:

sudo systemctl status mysqld.service
 mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor pres>
   Active: active (running) since Mon 2020-09-07 15:01:23 CST; 11min ago
 Main PID: 75615 (mysqld)
   Status: "Server is operational"
    Tasks: 40 (limit: 5045)
   Memory: 395.3M
   CGroup: /system.slice/mysqld.service
           └─75615 /usr/libexec/mysqld --basedir=/usr

Sep 07 15:01:12 iZa2dc2w6sz7gbkh2kc8exZ systemd[1]: Starting MySQL 8.0 database>
Sep 07 15:01:12 iZa2dc2w6sz7gbkh2kc8exZ mysql-prepare-db-dir[75531]: Initializi>
Sep 07 15:01:23 iZa2dc2w6sz7gbkh2kc8exZ systemd[1]: Started MySQL 8.0 database >
lines 1-13/13 (END)

The MySQL installation has been completed. Now you can connect the MySQL server without any password but we recommend securing the MySQL installation. The MySQL packages provide mysql_secure_installation command to apply the security. Just run the below command on terminal:

sudo mysql_secure_installation

and follow the on-screen instructions. Below are the details which require user input.

  • Press y|Y for Yes, any other key for No: y
  • Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
  • Re-enter new password: RE ENTER PASSWORD HERE
  • Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
  • Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
  • Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
  • Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
  • Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

5: Install PHP

Finally you can install PHP, by default CentOS ships with PHP 7.2. So you can install PHP using the following command.

sudo yum install -y php php-mysqlnd

After the installation is finished, you’ll need to restart the Apache web server in order to enable the PHP module:

sudo systemctl restart httpd

6: Verify the LAMP setup

Create a new file with the name info.php

sudo nano /var/www/html/info.php

Paste the following code in the editor and save the file.


Hit CTRL + X followed by Y and Enter to save and exit the file.

Now open your browser and point it to your external IP address of your server followed by info.php in the URL.


You will see the PHP information which indicates you have installed and configured Apache, MariaDB and PHP on your CentOS 8 server.


Now that we have installed LAMP STACK, you can now host your website in the server. One of the popular thing you can do is install WordPress and design your own website or blog for your business.

To manage MySQL with GUI, we need to install phpMyAdmin. Operations such as the management of databases, tables, indexes, permissions, and so on are executed with the graphical user interface of phpMyAdmin.

Hope this tutorial is helpful and comment down if you have any query or issue.