Script to install LAMP (PHP 7) on CentOS 6

Share this post to your friends !

WriteBash - 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-01 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-02 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.

If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.

Share this post to your friends !
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

single post bottom banner
«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.