LAMP Stack setup for CentOS 6

In this tutorial, we will show you the installation of LAMP stack for CentOS 6 based server. This tutorial assumed you have root access to your server. If you do not have direct root access, your login account should have at least [sudo] elevated privileges to proceed with this tutorial.


Linux Setup

Our How to Install CentOS 6.7 tutorial will cover the Linux aspect of the LAMP stack installation.


By default , http port is blocked hence you will need to unblock port 80 for web service.

sudo iptables -I INPUT 5 -p tcp -m tcp --dport 80 -j ACCEPT
sudo service iptables save
sudo service iptables restart


Apache Setup


Installing Apache on CentOS 6 with the following commands

sudo yum install httpd

Once Apache installation is completed. Start Apache with the following command.

sudo service httpd start


We can verify if Apache is working by accessing the server with http://your-server-ip-address

You should see similar Test page output if Apache is successfully started.



Update EPEL Repository

By default CentOS 6 repository provide only php 5.3 and MySQL 5.1 hence our tutorial will use remi repository to install php 5.6 and MySQL 5.5 instead.

Disabling IPV6 to speed up yum download (unless your server has ipv6 configured)

sysctl -w net.ipv6.conf.default.disable_ipv6=1
sysctl -w net.ipv6.conf.all.disable_ipv6=1
rpm -ivh epel-release-6-8.noarch.rpm
rpm -Uvh remi-release-6.rpm
nano /etc/yum.repos.d/remi.repo


Enable [remi] and [remi-php56] as show



MySQL 5.5 Setup

Next we will install MySQL with the following commands:

sudo yum install mysql-server
sudo service mysqld start
sudo chkconfig mysqld on

Next we will configure MySQL with the following command

sudo mysql_secure_installation

As this is a new installation without any existing root password , Hit Enter to continue.

Select Y when prompted you to set your new root password as shown.

You will be prompted with a series of questions after setting Root password . Simply type Y for yes on all of them, see the screen shot below:



PHP Setup

The following will install php with MySQL support and restart http service to apply the new settings.


Next We will install essential php module for Apache

sudo yum install php php56 php-gd php-mysql php-mcrypt

You should see that yum attempting to install php 5.6 as shown.


Restart httpd service

service httpd restart

To Test that your php is now working correctly, create a test.php at the following folder. Our tutorial use nano editor but you may use VI or any other text editor.

nano /var/www/html/test.php


You should see the following output when you access your test page http://your-server-ip-address/test.php



Delete the Test file as soon as you are satisfied with the verification.

Congratulation! You have completed your LAMP stack installation on your CentOS 6 Server.

You might want to consider setting up phpMyAdmin for the administration of MySQL


Was this article helpful to you?


Comments are closed.