Setting up LAMP Server with CentOS

One of the components of my undergraduate research class is to learn how to be a Linux administrator and as part of that, one of my tasks is to learn how to set up a LAMP server. Part of the reason for doing this, is that the particular server that I am setting up will be used in another class for a web site project they will be working on. In this post I will go through the steps I went through in setting up a LAMP server on CentOS 6. Below are step by step instructions on installing the software and getting things up and running. The steps assume you have already installed CentOS 6 and have a working Internet connection. That is something that is out of the scope of this post, so before continuing, make sure you meet that prerequisite.

1. Install Apache

The A in LAMP stands for Apache which is a web server. The web server is the software that can accept requests from a client (a browser) and sends back a response (a web page/HTML).

To start, open up and terminal and make sure you have root privileges by typing ‘su’. You will be prompted for the root password.

Once you have root, to install Apache enter this into the console:

yum install httpd

Once that is installed, you can start the service by typing:

service httpd start

To verify that it works, if you are using the desktop environment in CentOS you can just open a web browser and type:

If you are not using the desktop environment, you will want to find your CentOS I.P. address on your local network. To do this, type:

ifconfig eth0 | grep inet | awk '{ print $2 }'

You should see an I.P. address that looks similar to what computers on your network have. For me, that was ‘10.0.0.x’ and in my CentOS specific case, my I.P. address was Once you have this information, you can visit http://yourip and you should see a welcome page by Apache. If not…

If You Don’t See the Apache Welcome Page

CentOS is a very secure Linux distro and as a result, the firewall may be too aggressive. This is a good thing in a real world environment, but for learning purposes, we will disable the firewall to allow the web site to be seen. The firewall in Linux is called ‘iptables’, to disable it, we simply type:

service iptables save
service iptables stop

This should disable iptables and you should be able to view your site. Unfortunately, when you next boot up your CentOS machine, iptables will automatically start up, so lets turn that off by typing:

chkconfig iptables off

Start Apache Server on Bootup

Apache won’t start up by default when you boot your machine, so you’ll want to make sure that starts on boot. You can do this in a similar way to turning off iptables. Type this into the terminal:

chkconfig httpd on

Once this is done, Apache is installed and ready to go. Apache by default is installed to ‘/var/www’ and any pages you wish to display on your site goes in the ‘/var/www/html’ folder. If no page is specified, Apache will look for the index.html page by default. You can test this by placing a test page in the ‘/var/www/html’ folder. HTML is out of the scope of this tutorial, but if you’re messing with a web server, you should probably already know how to create an index.html page.

2. Install MySQL Server

The M in LAMP stands for MySQL. MySQL is a database management system (DBMS) that is very popular and powerful. Installing MySQL is pretty easy. To begin, again make sure you have root and type:

yum install mysql-server

Once the MySQL server is installed, start it by typing:

service mysqld start

Again, we will want to make sure MySQL starts on startup, so type:

chkconfig mysqld on

Securing your MySQL Server

The next thing we want to do is secure the MySQL server. To do this, run a script that comes with the MySQL installation by typing this into the terminal:


The prompt will ask you for your root password for the MySQL root user (not the Linux/CentOS root user). Since you haven’t set one up yet (first time install) it is blank, so simply press [Enter].

You will then be asked if you want to set a password for the root user. Do this now and make sure you remember it, as it is a pain to change/reset it!

The prompt will then as you a series of questions, to which you can reply yes to all of them. Once that is finished, your MySQL server is setup and ready to go. To verify this, type into the terminal:

mysql -u root -p

Type in your root password and it should bring up the mysql terminal. Then type:

show databases;

This will list all your databases. There should only be two right now. To quit the mysql promt, type ‘quit’. MySQL is successfully installed!

3. Install PHP

The last part of LAMP is PHP. PHP is a server side programming language that allows you to dynamically generate web pages/HTML. For the basic PHP install type:

yum install php

PHP is capable of many things but requires libraries to do so. You may want to install other PHP libraries to the server. To find out what libraries are available, type:

yum info php-

This will display a list of modules that can be installed. To view more information about them, type:

yum info name of module

You can install multiple modules at once and some of the ones I recommend to get started can be installed by typing:

yum install php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml

Verify that PHP is Working

To test that PHP is working, we can create a test page. Create a new file called ‘info.php’ in ‘/var/www/html’. Then, open up ‘info.php’ in your favorite text editor and type:

<?php phpinfo();?>

Save and close the file. Before we try to access the file, we may need to restart Apache so that the PHP installation will be recognized. To do this type:

service httpd restart

Once that is done, navigate to ‘http://your.server.ip/info.php’ and you should see a PHP page listing all the modules installed.

Once that is done, your LAMP server is ready to go!


This tutorial covered how to install the various components of a LAMP server. What I did not cover was properly setting up everything and allowing other users to have their own directory/web space. I plan on doing this in another tutorial. It should also be noted that this probably isn’t the most secure installation, especially because we disabled iptables. The correct method would be to allow the specific ports (for example, for Apache that would be port 80) through the firewall, whilst leaving the others closed. If you have any questions, comments or suggestions, please feel to leave a comment.


Extra Credit

Thanks to my Linux admin friend Joe for helping me early on to get started!

This entry was posted in Tutorials, Undergraduate Research and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


Are you human br0? * Time limit is exhausted. Please reload CAPTCHA.