Table of Contents
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: 192.168.56.3.
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 https://gitlab.com/Danny_Pham/WriteBash.com/raw/master/Install/05-Script_install_LAMP_PHP_7.2_on_CentOS_6.sh -O /home/install.shThen, you grant 700 permissions for the script as below.
chmod 700 /home/install.shFinally, execute the script.
bash /home/install.shAt 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.

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.

Next, run the following commands to check the status of the services.
Check out the httpd (Apache) service.
service httpd statusMysql service (MariaDB).
service mysql statusAnd finally, you can run the commands below to check the installed version of the package.
To check Apache version.
httpd -vMariaDB version, note: uppercase letters V.
mysql -VAnd check PHP version.
php -vConclusion
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).