How to setup LAMP Stack on CentOS 6.4/6.5/6.6

CentOS is a very popular Linux distribution mainly used as hosting server. This guide will show you step by step how to setup LAMP stack on CentOS 6.x version including CentOS 6.4, 6.5, and 6.6.

The guide starts by installing Apache web service, MySQL database, and PHP / suPHP. After completing this guide, the server is ready to host your web hosting services such as WordPress, Joomla, Drupal and more.

If you have a dedicated or VPS server and don’t want to buy cPanel, you can manually install and configure it as a WordPress, Joomla and Drupal web server. I use CentOS 6.4 running on a DigitalOcean VPS cloud servers. This should be applicable for any version of Centos such as Centos 5.x.

Install Apache

As root / superuser, update the system and install the web server (Apache)

yum -y update
yum -y groupinstall "Web Server"
chkconfig httpd on
chown apache.apache /var/www/html

Install MySQL database server

As root / superuser, install the MySQL database server

yum -y groupinstall "MySQL Database server"
service mysqld start

Install PHP and suPHP

PHP is used as the programming language in most CMSes such as WordPress, Magento, and Joomla, so we need to install PHP on our server.
suPHP is a tool for executing PHP scripts with the permissions of their owners. With suPHP you are able, for example, to manage php applications in user’s home directories without worry about permissions problems (when creating directories, files or uploads)

Run the following command to install the PHP

yum -y install php php-devel php-mysql apr-devel httpd-devel

We will install suPHP from source file so we need to install ‘Development Tools’ packages.

yum -y groupinstall "Development Tools"


tar zxv suphp-0.7.1.tar.gz

cd suphp-0.7.1
./configure --prefix=/usr --sysconfdir=/etc --with-apache-user=apache --with-setid-mode=paranoid  
--with-apxs=/usr/sbin/apxs --with-php=/usr/bin/php-cgi --with-logfile=/var/log/httpd/suphp_log  
--enable-SUPHP_USE_USERGROUP=yes --with-apr=/usr/bin/apr-1-config 

make && make install

Still in the current directory, copy the suphp.conf-example file configuration located in the doc folder to /etc/ directory.

cp doc/suphp.conf-example /etc/suphp.conf

Edit the /etc/suphp.conf file to be like below!

;Path to logfile


;User Apache is running as

;Path all scripts have to be in

;Path to chroot() to before executing script

; Security options

;Check wheter script is within DOCUMENT_ROOT

;Send minor error messages to browser

;PATH environment variable

;Umask to set, specify in octal notation

; Minimum UID

; Minimum GID

;Handler for php-scripts

;Handler for CGI-scripts

Add users / websites

To make it easy, websites in a server are divided by users. Users can upload their data or documents inside their HOME, mostly under public_html directory.

adduser website01
passwd website01
mkdir /home/website01/public_html
chown website01.website01 /home/website01
chown website01.apache /home/website01/public_html
chmod 711 /home/website01
chmod 750 /home/website01/public_html

You can simply repeat the above commands to add more users / websites

Configure the Apache HTTPD

– Edit the /etc/httpd/conf/httpd.conf file

ServerName <<<< --- change with your IP address and port
Listen  <<<< --- change with your IP address and port

NameVirtualHost *:80
# NOTE: NameVirtualHost cannot be used without a port specifier 
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.

# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
<VirtualHost *:80>
    DocumentRoot /home/website01/public_html
    ErrorLog logs/
    CustomLog logs/ common

	<Directory /home/website01/public_html/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all

<IfModule mod_suphp.c>
  suPHP_UserGroup website01 website01


– Edit the /etc/httpd/conf.d/php.conf file to make like below!

LoadModule suphp_module modules/
suPHP_Engine on
AddType application/x-httpd-suphp .php5 .php .php3 .php2 .phtml
<Directory />
    suPHP_AddHandler application/x-httpd-suphp

DirectoryIndex index.php

– Restart Apache and the server is ready to host WordPress/Joomla/Drupal and other CMSes.

/etc/init.d/httpd restart

– Test suPHP using a simple script file (test.php file) and locate it right under public_html directory.

<?php echo 'whoim = '.exec('/usr/bin/whoami');?>

– Run Firefox/Chrome and access to, it should echo who you are.