How to Install LAMP stack on CentOS 7

Install LAMP stack on CentOS 7

In this article, we will have explained the necessary steps to install and configure LAMP Stack on CentOS 7. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

LAMP is short for Linux, Apache, MySQL or PHP which is an open source web development platform. It uses Linux as it’s operating system while Apache and MySQL are used as a web & database servers, the PHP is also used as an object oriented scripting language to work as a complete web stack, which is used to prepare servers for hosting web content.

Install LAMP stack on CentOS 7

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo yum install epel-release
sudo yum update

Step 2. Installing Apache.

Run the following command with root user to install apache http server with yum repositories:

sudo yum install httpd

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

sudo systemctl start httpd
sudo systemctl enable httpd

Step 3. Installing MariaDB.

To install MariaDB type following command:

sudo yum install mariadb-server

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

sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Step 4. Installing PHP.

Add remi repository in CentOS so we can install latest PHP 7.2, typing following command:

sudo yum install

Now enable PHP72 package using below command:

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

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

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:

sudo systemctl restart httpd

Step 5. Testing PHP

Now you should create info.php file to test php to do so type following:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Then open the following link in your web browser and we will be able to see all the information about PHP and its other configurations: http://your-domain/phpinfo.php (replacing your IP address with the one above).

That’s all you need to do to Install LAMP Stack on CentOS 7. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.