Share your love
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 services ways on Linux.
In this article, we learn How to install the LAMP stack on Centos 7.
Steps 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 little difference between their system commands. Also in this instruction, we use MariaDB 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.
Step 1 – Prepare Centos 7 Server 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
Step 2 – Make LAMP Stack on Centos 7
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.
If you don’t see the image below, most likely your firewall is active.
Open the 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 MariaDB service on your Linux startup:
systemctl enable mariadb.service
4. Enter the following command to make the MariaDB security settings.
mysql_secure_installation
After entering press enter once and enter the MariaDB 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 an 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.
http://your-ip-address/info.php
Now you can see your PHP information through your web browser.
Conclusion
At this point, you have learned to install LAMP Stack on Centos 7. The LAMP stack includes the Linux OS, Apache, MariaDB or MySQL, and PHP. You can use this software for your web development. Hope you enjoy it.
For more guides and articles, you can visit the Orcacore website.