How to install LAMP stack on CentOS7 | TOSHOST LTD

How to install LAMP stack on CentOS7

What is LAMP stack?

The "LAMP" stack is a group of open-source software that is usually installed together so that the server can host dynamic websites and web apps. This actually represents the Linux operating system with Apache Web server. The website data is stored in the MySQL database and dynamic content is processed by PHP.

Now we will see, how to install LAMP stack on CentOS7. If you are the first among server users, then read the following blog.

Initial Server Setup with CentOS7

Let's go back to work.

Step – One

Install Apache

The Apache web server is currently the most popular web server in the world, a web server that is great for hosting a website.

We have to first install Apache web server in CentOS7 by the following command.

sudo yum install httpd

After installing it, you have to start the Apache service on the server.

sudo systemctl start httpd.service

After starting the Apache, open your Internet browser and type your server's IP address and press the Enter button. After loading your IP address, you will see a page like the image below.

If you see the above page, then understand that Apache is properly installed on your server. Now you have to enable the Apache with the following command.

If you want to see your public IP address here, then use the following command.


Step –Two

Install MySQL (MariaDB)

MariaDB is a community-developed branch of MySQL Relational Database Management System. Basically, it will organize and access the database where our site stores the information.

Now we will install MariaDB by using the following command.

sudo yum install mariadb-server mariadb

When your MariaDB installation is finished, you start MariaDB according to the command below.

sudo systemctl start mariadb


Now you have to install MySQL. Follow the following commands to install MySQL.

sudo mysql_secure_installation

Here you will be asked to enter the root password, you do not write anything and then press enter. And in the New Password and Re-enter the New Password box, type a new password.

Now you have to enable boot the MariaDB. Use the following command to enable boot.

sudo systemctl enable mariadb.service

Step – Three

Install –PHP (Hypertext Preprocessor)

PHP is basically a setup element for you, which processes the code to display dynamic content.

Here you have to install PHP and connect to the MySQL database. Use the following command to install PHP and connect with MySQL database.

sudo yum install php php-mysql

You need to turn on Apache server when you install PHP and to work with PHP.

sudo systemctl restart httpd.service

You can use some additional modules for PHP compliance. Use the following command to view the modules.

yum search php-

After implementing the command, you will see a brief description of php modules.

If you want to know more about the module or to manually install a module, then follow the command below.

yum infoyour_package_name

Suppose we can give command to know about php-fpm modules.

yum info php-fpm

And after you give this command you will get a lot of information about this. If we think that our php-fpm module is needed, we can install it through the following command.

sudo yum install php-fpm

Now we have finished our LAMP stack installation and configure. Now we will test PHP. The info.php file is located in /var/www/html/ on CentOS7. We will open this file using the following command.

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


After giving the above command, a blank file will open. You enter the following text into the file then save the file and close the file.

<?php phpinfo(); ?>

If you have a firewall running on your server, then use the following commands to allow HTTP and HTTPS traffic.

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


Now visit your server's IP address from your internet browser. example: youripaddress/info.php

You will see a page like below.

This file contains various types of information related to your server, so it should be deleted from the directory. Use the following command to remove the file.

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