How to install LAMP stack on CentOS7

blog background image

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.

curl http://icanhazip.com

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

Related Blog Post

Create, collaborate, and turn your ideas into incredible products with the definitive platform for digital design.

How to create cPanel backup from command line

12 December 2022

How to create cPanel backup from command line

This article explains how you can create cPanel backup from the command line, using your own username and password.

Read More
How to install Webuzo Panel on linux Server

12 December 2022

How to install Webuzo Panel on linux Server

Webuzo is a popular alternative to cPanel, a widely used web hosting control panel developed by cPanel, Inc.

Read More
What are NFT Domains?

02 February 2022

What are NFT Domains?

NFT domains are new web extensions that are deployed using ERC 721 and Polygon Network, except .zil which uses Zilliqa.

Read More
How to Delete a MySQL® Database

01 January 2022

How to Delete a MySQL® Database

This document describes how to manually delete a MySQL® database from a cPanel & WHM server. This is useful if, for exa

Read More
How to get Transfer Authorization Code from GoDaddy

11 November 2021

How to get Transfer Authorization Code from GoDaddy

To transfer your domain with us then must need EPP Code.

Read More

Got a question!

Contact us at