How to install LAMP stack on centos 7

The LAMP is web service software that stands for phrase Linux, Apache, MySQL, and PHP.
Lamp stack is one of the most popular web service ways on Linux.
In this article, we learn How to install the LAMP stack on centos 7.

How to install LAMP stack on centos 7

The installations of Lamp stack on these two popular versions of Linux CentOS 6 and CentOS 7 are the same and there is a little difference between their system commands. Also in this instruction, we use Maria DB as a database instead of MySQL.

Note: If you are connecting with a non-root user to your Linux, you should use the sudo command on the first of all your commands. you can check our article about the Initial server setup with Centos 7.

Prepare centos 7 for LAMP stack installation

1. Set the Hostname on centos 7.

hostnamectl set-hostname lamp.orcacore.net

Remember, replace your desired name instead of lamp.orcacore.net

Note: If you want to change your hostname after installation of the lamp stack you may see some errors.

2. Update the date and time of your Linux with this command:

ntpdate time.windows.com

3. Update Linux centos 7 with this command:

yum -y update

4. Then reboot your Linux.

reboot

Make lamp stack

Now you are ready to install the LAMP stack on centos 7.

Install Apache

1. First of all install the Apache webserver with the following command:

yum install -y httpd

2. With the following command start the Apache:

systemctl start httpd.service

3. Finally, add Apache to your Linux startup with the following command to run automatically every time you reboot:

systemctl enable httpd.service

After installation to ensure the performance of Apache on the server enter your server’s IP address in the browser once until it displays a similar image below.

test page apache on centos 7
If you don’t see the image below, most likely your firewall is active.

Open webserver port with the following command:

sudo firewall-cmd --zone=public --add-service=http –permanent

Then enter the following command to reload your firewall:

sudo firewalld-cmd –reload

You can get a full look at our article about how to set up a Firewall with firewalld on Centos 7.

Install and configure MariaDB

At this point, to install the LAMP stack you need to install MariaDB.

1. Install the MariaDB package with the following command:

yum install -y mariadb-server mariadb

2. Then start Maria DB service:

systemctl start mariadb

3. Finally enter the Maria DB service on your Linux startup:

systemctl enable mariadb.service

4. Enter the following command to make the Maria DB security settings.

mysql_secure_installation

After entering press enter once and enter the Maria DB login password. (default password is empty)

In the following steps, answer the other questions to your liking. It is suggested that you answer Y in all the questions to set the best state.

Install PHP

To install the lamp stack on centos 7 you need to install PHP too.

1. Enter the following command to download and install PHP.

yum install -y php php-mysql

2. Restart the apache service to recognize PHP.

systemctl restart httpd.service

PHP is installed in this section, if you need to install other PHP modules, you can see the available modules with the following command:

yum search php-

After finding your module installs it with the yum command. Like this following command:

yum -y install php-mbstring.x86_64

Finally, the following technique ensures that PHP is installed correctly and runs correctly in Apache.

•Create a info.php file at var/www/html/ address.

vi /var/www/html/info.php

•Copy the following code into it and save the file.

<?php
phpinfo();

•Then open your browser and enter your server’s IP address with the /info.php like the following phrase.

your-ip-address/info.php

Hope you enjoy this article about How to install the LAMP stack on centos 7.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular