| More

There’s an easy way of installing Apache, Mysql and PHP and it’s via yum. You can install or update httpd,mysql-server and php, php-mysql and some minor changes on your configuration files and you’re good to go. Well, the procedure below is one way to install also, if you’re quite bored and want to develop your sysadmin skills.

I. Operating System Installation

1.    The typical type of installation is thru  CD-ROM or DVD. If you want network install, you should have a CentOS boot disk to boot the server

How to create boot disk?
A. how to create boot disk in linux
a. insert CD then copy boot.iso to a folder

#cp boot.iso /home/test/

b.unmount the cd-rom

#cd; eject

c. Insert the blank cdr and find the dev name

cdrecord -scanbus

d. Write the .iso to that blank cd

#cdrecord -v -dao dev=1,2,3 /home/test/boot.iso

the 1,2,3 value is just a sample. Just replace it with the actual device name that you get upon running
the cdrecord -scanbus.

B. how to create boot disk in windows
a. copy boot.iso in any folder
b. run your favorite cd burning program and open boot.iso
c. start the cd writing process

2.    Assign a static IP address & the hostname for the server.

3.    Select network install from FTP or NFS depends on your setup
path: /pub/centos5

Setting up NFS or FTP is discussed on the other tutorial

4.    When finish, do the update. The -y parameter denotes automatic update and install of the package, no more prompt.

#yum –y update

5.    Configure the file “network” at /etc/sysconfig/network with the following lines.


6.    Configure the file “ifcfg-eth0” at /etc/sysconfig/network-scripts/ifcfg-eth0 with the following lines.

# Broadcom  Gigabit Ethernet
IPADDR=Static IP Address (Example:
NETMASK=Subnet Mask (Example:
GATEWAY=Gateway IP address (Example:

7.    Configure the file “hosts” at /etc/hosts with the following lines. (optional)

# Do not remove the following line, or various programs
# that require network functionality will fail.               localhost.localdomain localhost              c5.freelinuxtutorials.com c5 (Add the server hostname here)
::1             localhost6.localdomain6 localhost6

8.    Configure your DNS  at /etc/resolv.conf with the following lines.

nameserver Primary DNS (Example:
search freelinuxtutorials.com

9.    Restart the network interface by the following commands.

#service network restart

10.   Close unnecessary services via the “setup” menu tool or  use chkconfig to turn off auto start of certain services

#chkconfig cups off
#chkconfig nfslock off

11.     After first restart, check your logs to see some errors

cat /var/log/messages |grep error
cat /var/log/messages |grep warning

II. Apache Installation

1.    Apache can be installed as package during custom selection of packages on the installation process, labeled as “Web Server”

2.   Make Apache service start on boot-up via:

# chkconfig httpd on

Let say the default version of your apache is 2.2.3 and you want to upgrade it to the latest version


1.    # yum remove httpd

httpd                   x86_64        2.2.3-7.el5.centos  installed         2.9 M
Removing for dependencies:
httpd-devel             x86_64     2.2.3-7.el5.centos   installed         512 k
httpd-devel             i386         2.2.3-7.el5.centos   installed         512 k


shell#  rm –rf  php-5.2.3

3.    Download httpd-2.2.4-4.x86_64.rpm from http://rpmfind.net/
4.    Download httpd-devel-2.2.4-4.x86_64.rpm from http://rpmfind.net/
5.    Download lib64db4.5-4.5.20-1mdv2007.1.x86_64.rpm http://rpmfind.net/
6.    Install lib64db4.5-4.5.20-1mdv2007.1.x86_64.rpm

Shell# rpm –Uvih lib64db4.5-4.5.20-1mdv2007.1.x86_64.rpm

7.    Install httpd-2.2.4-4.x86_64.rpm

Shell# rpm –Uvih httpd-2.2.4-4.x86_64.rpm

8.    Install httpd-devel-2.2.4-4.x86_64.rpm

Shell# rpm –Uvih httpd-devel-2.2.4-4.x86_64.rpm

G.   MySQL Installation

1.    Download the MySQL software at http://www.mysql.org.

2.    Select Linux Source to download. File name should be “mysql-5.0.41.tar.gz”

3.    Before installation, ensure that gcc compiler has installed. Please verify by

gcc –v

If gcc does not install, please install it by

yum install gcc

4.    Install gcc-c++ compiler by

yum install gcc-c++

5.    Install the ncurses-devel library by

yum install ncurses-devel

It is require by the MySQL during compile process.

6.    Run the following commands.

shell> groupadd mysql
shell> useradd -g mysql mysql
shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
shell> cd mysql-VERSION
shell> ./configure --prefix=/usr/local/mysql
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql var
shell> bin/mysqld_safe --user=mysql &

7.    To make MySQL start automatically after reboot, do the following.

shell> cp /mysql-VERSION/support-files/mysql.server /etc/init.d/mysql
shell> chmod +x /etc/init.d/mysql
shell> chkconfig --add mysql

8.    To test the MySQL, type the following command.

shell>/usr/local/mysql/bin/mysqladmin version

If it can display the version, installation is preliminary success.

9.    Do the following simple testing.


mysql> show databases;
| Database           |
| information_schema |
| mysql              |
| test               |
3 rows in set (0.02 sec)

mysql> use mysql;

Database changed

mysql> show tables;

| Tables_in_mysql           |
| columns_priv              |
| db                        |
| func                      |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| proc                      |
| procs_priv                |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
17 rows in set (0.00 sec)

mysql> select * from db;

| Host | Db      | User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Create_tmp_table_priv | Lock_tables_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Execute_priv |
| %    | test    |      | Y           | Y           | Y           | Y           | Y           | Y         | N          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | N                  | N            |
| %    | test\_% |      | Y           | Y           | Y           | Y           | Y           | Y         | N          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | N                  | N            |
2 rows in set (0.00 sec)

10.    Add password for “root” in MySQL Database by typing the following commands. The default password is same as Linux root password.

shell> mysql -u root mysql

mysql> UPDATE user SET Password=PASSWORD(‘default password’) WHERE user=’root’;


11.     Test it by the following commands.

shell>mysql - u  root - p
Enter password: ********

H.    PHP Installation

1.    Download the tar.gz file with filename “php-5.2.3.tar.gz” at http://www.php.net

2.    Install Flex by,

yum  install flex

3.    Install libxml2 by

yum install libxml2-devel.x86_64

4.    Install httpd-devel by

yum install httpd-devel

5.    Uninstall the installed php by

yum remove php

6.    Type the following commands.

shell> gunzip < php-VERSION.tar.gz | tar -xvf –


shell> tar zcvf php-VERSION.tar.gz
shell> cd php-VERSION
shell> ./configure --with-apxs2 --with-mysql=/usr/local/mysql/ --prefix=/usr/local/php
shell> make
shell>make install
shell> cp php.ini-recommended /usr/local/php/php.ini

7.    Modify httpd.conf by

vi /etc/httpd/conf/httpd.conf

Add the following two lines after all “AddType” or after “AddType application/x-gzip .gz .tgz”.

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Add the following line after all “LoadModule”.

LoadModule php5_module modules/libphp5.so

8.    To test, prepare a file with filename “index.php” with the following contents.


Store it in /var/www/html/

9.    Remarks all line in the file /etc/httpd/conf.d/welcome.conf

10.    Restart the Apache server by

/etc/init.d/httpd restart

11.    Use IE to access the server by



3 Responses to “CentOS LAMP Installation”

  1. Bytza

    on October 17 2012

    Thankyou for this great tutorial.

  2. Free Linux Tutorials

    on October 18 2012

    no problem. thanks for dropping by 🙂

  3. glashio

    on April 5 2013

    Thanx 🙂 Couldn’t find Apache 2.2.4 on ftp://rpmfind.net/linux/centos/5.9/os/x86_64/CentOS/ :'( For my CentOS 5.9 (Final) I want to use mod_spdy, can you help?

Comment RSS · TrackBack URI

Leave a comment

Name: (Required)

E-mail: (Required)




About FLT

This site is dedicated to everyone who likes to learn and explore the beautiful world of Linux. If you have comments and suggestions, please feel free to email at freelinuxtutorials@gmail.com. I am happy to serve and share things esp. that is free and enjoyable as Linux.