Script to install LAMP (PHP 7) on CentOS 6

by Daniel Pham
Published: Updated:

Today, I wrote a script to install the LAMP stack on CentOS 6, using PHP 7.2. This article will guide you through the script to install LAMP (PHP 7) on CentOS 6 quickly.

About this script

Script will install the LAMP stack on CentOS 6 with just a few commands. Basic features of the script.

  • Check if the script is executed by the root user.
  • Check the state of SELinux, disable it if it is in enforcing state.
  • Update the package.
  • Installing the LAMP stack includes: Apache, MariaDB, PHP.
  • Set up the iptables rules to serve the web server.

Versions of software to install.

  • Apache: 2.2.15.
  • MariaDB: 10.2.13.
  • PHP: 7.2.3 (use Remi’s repository).

Server requirements

To use this script, your server needs to meet the following requirements. This script was tested successfully on CentOS 6.9 Final 64bit.

  • OS: CentOS 6.9 Final 64 bit, install basic server.
  • RAM: over 1GB memory, recommend 2GB.
  • HDD: 5GB free space.
  • User: root
  • IP: set static IP, ex:

Use script to install LAMP on CentOS 6

Note: PHP uses repository of Remi, this is a repository with quite a lot of users. But I still want to remind you that you can consider using it.

First, download the script with the following command.

wget -O /home/

Then, you grant 700 permissions for the script as below.

chmod 700 /home/

Finally, execute the script.

bash /home/

At first execute the script, it will check the selinux status on your server. If it is enforcing, it will automatically disable selinux and reboot after 5 seconds. In this step, you can press Ctrl + C to abort the script.

Script to install LAMP (PHP 7) on CentOS 6
Script completes the installation of LAMP stack.

After the server has finished rebooting, you run the script again to install the LAMP stack. Depending on the internet connection it can take from 10 to 15 minutes to complete the installation.

Check the results

Now we will check the results after installing LAMP. First, try to visit the info.php page to see if PHP works well with Apache.

Script to install LAMP (PHP 7) on CentOS 6
Visit the info.php page to test PHP’s performance with Apache.

Next, run the following commands to check the status of the services.

Check out the httpd (Apache) service.

service httpd status

Mysql service (MariaDB).

service mysql status

And finally, you can run the commands below to check the installed version of the package.

To check Apache version.

httpd -v

MariaDB version, note: uppercase letters V.

mysql -V

And check PHP version.

php -v


I tested the script on a 64-bit CentOS 6.9 Final virtual server. It really works and I believe it will also work for you. With this script, you can install the LAMP stack very quickly without worrying about making any mistakes. Now, the rest of you are starting to set up virtualhost and upload your website source.

(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).

0 0 votes
Article Rating

You may also like

Notify of
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.



Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 – All rights reserved.

Please write sources “” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Would love your thoughts, please comment.x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.