How to Install LAMP Stack on CentOS 8


The LAMP stack is a set of open-source software used for web application development. It consists of a Linux operating system, an Apache HTTP server, the MySQL database management system, and PHP programming language.

In this tutorial, learn how to install the LAMP stack on CentOS 8.

How to install LAMP stack on CentOS 8.


  • A server running CentOS 8 Linux
  • A terminal window/command line (Search > terminal)
  • A user account with sudo or root privileges
  • The yum and RPM package managers, included by default

Follow the installation steps outlined below and install the required software in the specified order. As this guide is for CentOS 8 users, it skips the first layer of the stack (the Linux operating system), presuming it has already been installed.

Step 1: Update System Software Packages

Open a terminal window and update the package repository before installing new software:

sudo yum update

Step 2: Install Apache

1. Install Apache Web Services with the command:

sudo yum –y install httpd

Apache successfully installed on CentOS 8 server
2. Then, start the Apache service by running:

sudo systemctl start httpd.service

3. To verify Apache is running, open a web browser and navigate to the server’s public IP address. It should display the Apache Test Page, as in the image below.

apache is running on centos 8

Note: For additional details, refer to our article on how to install Apache on CentOS 8.

Step 3: Install MySQL

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.

In this example, the tutorial includes a MySQL installation. Alternatively, you can install MariaDB.

1. Start by adding the MySQL repository:

rpm –ivh

2. Check the repository by typing:

sudo yum repolist all |grep mysql | grep enabled

The output should display a list of the different MySQL options available.

output of a list of MySQL repositories

3. Now, install MySQL:

sudo yum ––disablerepo=AppStream install –y mysql-community-server

example of installing mysql

4. Then, enable the MySQL service and set it to start on boot:

sudo systemctl start mysqld
sudo systemctl enable mysqld

5. Check whether the service is running properly with the command:

sudo systemctl status mysql

The output should display the service is active (running).

Checking the MySQL status

Note: To easily manage MySQL databases, admins often opt to install PHPMyAdmin.

Step 4: Configure MySQL Security

The next step is to configure the basic MySQL security settings.

1. Start by displaying the temporary MySQL root password:

cat /var/log/mysqld.log | grep –i ‘temporary password’

The system displays the temporary MySQL password.

Prompt MySQL for temporary password to configure security.

2. Next, run the command:

sudo mysql_secure_installation

Provide the MySQL root password received in the previous step.

3. Then, enter and re-enter a new password, making sure it meets the standards for password strength.

4. After updating the password, you are prompted again to change the root password. To do so, type y and hit Enter.

5. The output displays the estimated strength of the password. Press y to continue with the password provided.

Answer the rest of the questions with y and Enter:

      • Remove anonymous users? (y)
      • Disallow root login remotely? (y)
      • Remove test database and access to it? (y)
      • Reload privilege tables now? (y)

With this, MySQL is secured.

Output displaying you have successfully secured the MySQL database.

Note: For an in-depth guide and additional instructions, please refer to How to Install MySQL on CentOS 8.

Step 5: Install PHP and Supporting Modules

Set up the final layer by installing the PHP programming language and the supporting modules for phpMyAdmin:

sudo yum –y install php php-pdo php-pecl-zip php-json php-common php-fpm php-mbstring php-cli php-mysqlnd wget upzip

PHP installed on CentOS 8 as part of the lamp stack

Then, enable the PHP module to work with Apache by restarting the webserver:

sudo systemctl restart httpd.service

Step 6: Adjust the Firewall

If you have firewalld set up on CentOS, you need to adjust the configuration to allow Apache connections.

1. Open the firewall for HTTP traffic with the command:

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

2. Next, adjust it to allow HTTPS traffic as well:

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

3. Restart the firewall for the changes to take place:

sudo firewall-cmd --reload

4. Check to verify HTTP and HTTPS routes are now permanently open by running:

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

The output should display http and https in the list of services.

List open firewall routes

Step 7: Test PHP with Apache

Apache creates a web root file in the default website directory /var/www/html/. To check whether PHP is set up properly by running a test from this directory.

1. Create a info.php file inside the directory:

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

2. Then, add the following content:


phpinfo ();


3. Save and exit the file.

4. Now, verify if PHP is working correctly. Open a web browser and navigate to the URL (replacing ip_address with the public IP of the server):


The browser should display the content, as in the image below.

verification of PHP installation on centos 8

Note: Want more details about this open-source software bundle? Refer to What is a LAMP stack?


You should now have a working installation of LAMP Stack on your CentOS 8 system.

Next, explore other stack alternatives such as the XAMPP stack or the MEAN stack.

Sofija Simic
Sofija Simic is an aspiring Technical Writer at phoenixNAP. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
Next you should read
How to Install phpMyAdmin on CentOS 7
October 22, 2018

This guide is for users who have already configured a CentOS server...
Read more
What is a LAMP Stack?
March 7, 2019

The LAMP stack is a set of open source software used for web application...
Read more
How to Install Apache on CentOS 8
February 6, 2020

The Apache web server is widely used, especially as part of the LAMP stack...
Read more
How to Install MySQL on CentOS 8
February 17, 2020

MySQL, the most widely used relational database management system can be...
Read more
  • © 2021 Copyright phoenixNAP | Global IT Services. All Rights Reserved.