Install LAMP Stack on CentOS 8

A 5-part series covering lamp and centos

By Dejan Panovski

Updated on

5 parts

Install LAMP Stack on CentOS 8

The term LAMP is an acronym of the names of the following four open-source components:

  • L - Linux operating system.
  • A - Apache, the world’s most popular HTTP web server.
  • M - MySQL or MariaDB relational database management system.
  • P - PHP programming language.

The LAMP stack is generally used for developing and deploying dynamic PHP applications such as WordPress, Laravel, and Drupal.

In this series, we’ll cover how to install Apache, generate a free Let’s Encrypt SSL certificate, install and secure MySQL, and install PHP 7.

If you are in a hurry and don’t want to read more detailed documentation, you can install LAMP Stack on your CentOS 8 server by following our Quickstart section.

Install LAMP Stack on CentOS 8 [Quickstart]

This quickstart shows the basic steps required to get a LAMP stack installed on a CentOS 8 server.

Prerequisites

The user you are logged in as must have sudo privileges to be able to install packages.

Step 1. Installing Apache

Apache is available in the default CentOS 8 repositories, and the installation is pretty straightforward.

On RHEL-based distributions, the Apache package and the service are called httpd. To install the package, run the following command:

Terminal
sudo dnf install httpd

Once the installation is completed, start and enable the Apache service by typing:

Terminal
sudo systemctl enable --now httpd

Step 2. Installing MySQL

The next step is to install MySQL or MariaDB database server. To do so, type:

Terminal
sudo dnf install @mysql

Once installed, start and enable the service with:

Terminal
sudo systemctl enable --now mysql
Info
If you want to install MySQL instead of MariaDB, check our tutorial for installation instructions.

Run the mysql_secure_installation script to secure your server and set the MySQL root password:

Terminal
mysql_secure_installation

You will be asked to configure the VALIDATE PASSWORD PLUGIN , which is used to test the strength of the MySQL users’ passwords and improve the security. There are three levels of password validation policy, low, medium, and strong. Press ENTER if you don’t want to set up the validate password plugin.

Step 3. Installing PHP

CentOS 8 is distributed with PHP 7.2. This version supports most of the modern PHP applications, but will no longer be actively maintained as of November 2019. The newer PHP versions are available from the Remi repository. We’ll install PHP 7.4.

Run the following command to install the Remi repository and enable PHP 7.4:

Terminal
sudo dnf install dnf-utils https://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo dnf module reset php
sudo dnf module enable php:remi-7.4

Install PHP FPM and several of the most common PHP modules by typing:

Terminal
sudo dnf install php php-opcache php-gd php-curl php-mysqlnd

FPM is installed as a dependency and used as a FastCGI server. Start the FPM service and enable it to automatically start on boot:

Terminal
sudo systemctl enable --now php-fpm

If SELinux is running on your system, you’ll need to update the SELinux security context:

Terminal
sudo chcon -Rt httpd_sys_rw_content_t /var/www

Restart the Apache service for changes to take effect:

Terminal
sudo systemctl restart httpd

More Information

For more detailed instructions about each step, please consult the following tutorials.

Articles