Install LAMP Stack on CentOS 7

A 4-part series covering lamp and centos

By Dejan Panovski

Updated on

4 parts

Install LAMP Stack on CentOS 7

The term LAMP is an acronym of the names of its 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

In this series, we will show you how to install Apache, generate a free Let’s Encrypt SSL certificate, install and secure MariaDB, and install PHP 7.x.

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

Install LAMP Stack on CentOS 7 [Quickstart]

This quickstart will show you the basic steps required to get a LAMP stack installed on a CentOS 7 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 7 repositories and the installation is pretty straightforward. On CentOS and RHEL, the Apache package and the service are called httpd. To install the package, run the following command:

Terminal
sudo yum install httpd

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

Terminal
sudo systemctl start httpd
sudo systemctl enable httpd

Step 2. Installing MariaDB

The next step is to install the MariaDB packages. To do so, type:

Terminal
sudo yum install mariadb-server

Once MariaDB server is installed, start and enable the service with:

Terminal
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
Info
At the time of writing, MariaDB 5.5 is available in the official CentOS 7 repository. If you want to install a newer version please refer to this tutorial . To install MySQL instead of MariaDB, check our tutorial for installation instructions.

Step 3. Installing PHP

CentOS 7 ships with PHP version 5.4 which has been EOL for quite some time, so we’ll use the Remi repository to install PHP 7.2.

Run the following command to install the Remi repository to your system:

Terminal
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

Once it is added, install the yum-utils package and enable the remi-php72 repository:

Terminal
sudo yum install yum-utils
sudo yum-config-manager --enable remi-php72

Now that we have the Remi repository enabled, we can install PHP FPM and several of the most common PHP modules with:

Terminal
sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql

Once the PHP packages are installed, restart the Apache service with:

Terminal
sudo systemctl restart httpd

More Information

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

Articles