LAMP: Linux, Apache, MySQL and PHP

Posted by on Apr 30, 2016 in Linux Help | 0 comments

There’s many a time we need a CentOS node setup with Apache, PHP, and MySQL.  See how we provision our server(s).


LAMP is a collection of open source software to run web servers. LAMP is an acronym for (Linux, Apache, MySQL and PHP). This tutorial is going to assume that you already have CentOS 6 installed. You should also have some basic knowledge of how to operate the console and some basic knowledge of shell as well. You need to make sure you have root privileges and that you know how to access root shell before you begin.

Choose An Editor

Before we begin the installation process, we need to choose a text editor. For this guide, Nano will be the recommended text editor of choice. You can use Vim, but it’s slightly more complicated than Nano.

Updating Your System

You need to run some updates after a fresh CentOS6 install. To do this, type:

yum update

Make sure you have all of the possible updates selected and let them complete. After that’s finished, you’ll run the following:

cat /etc/*release*

When you type that in, you should the CentOS version you’re currently running. At the time of this tutorial (5/24/2015), the correct version should be: 6.6

SELinux Setup

Next, we need to either disable or setup SELinux. It’s recommended that you disable SELinux because it’s not uncommon to receive errors when you’re running the LAMP stack. To disable SELinux (recommended), do the following:

nano /etc/selinux/config

You’ll notice a SELINUX line. To disable it, simply change the line to disabled by doing:


After this is done, you need to reboot the machine by typing:

shutdown -r 0

Setting Up The EPEL Repository

Since EPEL isn’t included in your base repository and EPEL comes with some extra helpful software, we’re going to need to set that up.

Simply run:

yum install epel-release -y yum update

The EPEL repository should now be installed and updated

The Installation Of Apache, MySQL and PHP

Install Software

First, start off with the following command:

yum install mysql mysql-server mysql-devel httpd php-common php-gd \
php-pear php-pecl-memcache php-mysql php-xml php \ 
php-mcryptphp-mbstring php-devel gcc pcre-devel -y

Enable Software

Next, we’ll need to enable MySQL and Apache on startup. To do so, simply issue the following command:

chkconfig httpd on chkconfig mysqld on

The following command will ensure that Apache and MySQL start

service httpd start service mysqld start

If everything was done right up to this point, you should then see a dialogue from MySQL notifying you to change your password.

Run the command:


You will be taken through a series of prompts. All the defaults should be fine so simply hit enter on them all except for the one asking you to set the MySQL root password. Make sure to choose a strong password. This root password is different from the root password of your server.


If everything has been setup correctly, you should be able to reach your web server using the IP in a web browser. Congratulations, you have installed your first LAMP Stack on CentOS.

Further Configuration

Sometimes the default configuration values are not enough and need modified. This section will briefly go over some of the settings that you can change.

Apache Configuration

nano /etc/httpd/conf/httpd.conf

Next, you need to allow for .htaccess overrides. To do this, search for the allowoverride function. Once you see it, just simply change:

AllowOverRide None


AllowOverRide All

If there’s a hashtag in front of AllowOverRide All, you need to remove it.

Configuring PHP

First thing’s first, we need to edit the PHP configuration.

nano /etc/php.ini

We’re going to change the maximum upload file size and you can change this to whatever you want but for the purpose of this tutorial, let’s just change it to 50M. Search for the following settings and change them

upload_max_filesize = 50M post_max_size = 128M

You may not need to do the next step but we’re going to increase the memory limit here. 128 is the default and reasonable but in some cases, you might require more.

memory_limit = 256M

To make the changes go into effect, restart httpd:

service httpd restart

Setting Up Apache With Virtual Hosts

To add virtual hosts, which allow multiple websites to be served with just one Apache installation, all we have to do is edit the configuration. For the example below, we’ll use two web hosts:

You need to edit / add this in your httpd configuration file:

NameVirtualHost *:80 
<VirtualHost *:80>
DocumentRoot "/var/www/html" </VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/html/" </VirtualHost>

Setting Up Cron Jobs

The one and final step we need to take is to setup cron jobs. Why is this important? This will allow us to schedule tasks and to accomplish this, we’re going to need Crontab and CRON. Issue the following commands:

yum install crontabs -y chkconfig crond on

To add a cron job you can add an entry in cron tab via:

crontab -e

Finally, we’ve reached the end of the guide on installing LAMP with CentOS 6.6 . By the end of this guide you will have installed Apache, MySQL and PHP and are ready to get your first website up and running. Enjoy.

Leave a Reply

Your email address will not be published. Required fields are marked *