How to install a full LAMP stack on CentOS 8

With the latest release of CentOS out, you'll want to know how to install a full-on LAMP stack onto this powerhouse, open source platform.

How to install a full LAMP stack on CentOS 8

CentOS is quite often the operating system of choice for web and network admins alike. The reasons for this are many, but security and reliability always rise to the top of that list. But some might assume CentOS not quite the best choice for those new to Linux. In some instances, that might be the case, but not always.

In fact, there are instances where CentOS is just as easy to administer as Ubuntu Server. Although installing a LAMP stack on CentOS might not be such an instance (as there is no equivalent to sudo apt-get install lamp-server^ on CentOS), it's not nearly as challenging as you might expect.

Case in point, adding a full web stack to your CentOS server can be done by any IT admin of any skill level. In fact, I'm going to show you how to do just that, on the latest release of the platform, CentOS 8. 

SEE: 10 free alternatives to Microsoft Word and Excel (TechRepublic download)

What you'll need

The only things you'll need to make this happen are:

  • A running instance of CentOS 8

  • A user with sudo privileges

Making sure CentOS is up-to-date

The first thing we want to do is make sure CentOS is up-to-date. Log in to your CentOS 8 server and issue the command:

sudo yum update -y

Once the update completes, reboot (only if the kernel was updated), and continue on.

How to install Apache

Next, we'll install the Apache web server. To do that, issue the command:

sudo yum install httpd httpd-tools -y

When the installation completes, start and enable the http daemon with the commands:

sudo systemctl start httpd
sudo systemctl enable httpd

How to alter the firewall rules

The installation of Apache does not alter the firewall rules, so we have to do that manually. To allow traffic in on port 80, su to the root user and issue the command:

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

You might want to also allow HTTPS traffic in on port 443 with the command:

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

Reload the firewall with the command:

systemctl reload firewalld

Unlike Apache on Ubuntu, this installation doesn't add a default welcome page for the web server. Let's create a sample page to make sure the server is working. To do this, issue the command:

echo <h2>"Welcome to <a href="" target=blank>TechRepublic</a></h2>" > /var/www/html/index.html

Point your browser to the IP address of your server and you should see the test page (Figure A).

Figure A


Our new test page.

Exit out of the root user with the command:


How to install the database

Now it's time to install the database. I'm going to opt for MariaDB. To install this database, issue the command:

sudo yum install mariadb-server mariadb -y

After that installation completes, start and enable the database with the commands:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Now we need to secure the database installation with an admin user password. To do that, issue the command:

sudo mysql_secure_installation

You will be prompted to type the current admin user password. Since there is none, just hit Enter. Next type and verify a new admin user password. After you've set the password, you'll answer Y to the following questions:

  • Remove anonymous users?

  • Disallow root login remotely?

  • Remove test database and access to it?

  • Reload privilege tables now?

How to install PHP

To install PHP and a few necessary modules, issue the command:

sudo yum install php php-fpm php-mysqlnd php-opcache php-gd php-xml php-mbstring -y

When that installation completes, start and enable PHP with the commands:

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Congratulations, you now have a fully-functioning LAMP server, with CentOS 8 as its foundation. You can now start developing web sites and web applications that depend on these tools. 

Also see


Image: CentOS