LAMP server setup

LAMP stands for Linux Apache ,Mysql and PHP . As the name implies we should keep the same order while installing the softwares.

This doc is explaining  the compilation of apache and  php from latest source.  Here apache is compiled as DSO and php  as apache module.

Install latest softwares

wget http://apache.oss.eznetsols.org//httpd/httpd-2.2.19.tar.gz
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-5.5.13-1.linux2.6.i386.tar/from/http://mirror.csclub.uwaterloo.ca/mysql/
wget http://sg.php.net/get/php-5.2.17.tar.gz/from/this/mirror

Here i have used the above version’s , you can use the necessary versions from the below sites.

http://httpd.apache.org/download.cgi    |    http://dev.mysql.com/downloads   |      http://php.net/downloads.php

####  Install and compile apache as DSO ####

DSO stands for dynamic shared object.  If we compile apache as dso then we can add additional modules with out disturbing the working/production server . Here we are using the apache tool ” apxs – stands for apache extended service ” to achieve this . I will explain more about DSO later in this doc.

# yum install gcc gcc-c++

# tar -zxf httpd-2.2.19.tar.gz

cd httpd-2.2.19

make clean

# ./configure --prefix=/usr/local/apache --enable-shared=max --enable-module=rewrite --enable-module=so

( configure will help to customize the installation and also it will check and confirm all the necessary packages and dependencies are installed )
make

(make will compile the necessary modules )

make install

( make install will install the binary to the directory mentioned in prefix )

Once everything is completed with out any error’s , that fine. You have completed apache installation .

All the necessary configuration files and binaries  are will be in /usr/local/apache

/usr/local/apache/bin/apachectl -k  start

After starting apache  just confirm its running fine.
ps aux | grep httpd

If everything is fine then try to browse your web server ip  . You will get a apache default page ” its works ! ”

If you want to tune your apache server for better performance then try this : Apache performance tuning

####  Install   Mysql #####

Download necessary package (rpm) from the mysql website and install using rpm command.

#   tar -xf  Mysql-*

rm -f  *-test-*.rpm ( remove the test rpm )

rpm -ivh *

(Install rest of the rpm’s )

Once you complete the installation as above , setup a root password for mysql using the command

start mysql using

/etc/init.d/mysql start

After restarting the mysql service , set a root password for security purpose.

/usr/bin/mysqladmin -u root password  ‘new root password’

Test and confirm mysql installation is perfect

# mysql -u root -p

> create database admin;

>exit

Check and the database is created in /var/lib/mysql , which is the default data directory.

#### Install and Compile php as apache module ####

yum install gd   gd-devel   libxml2-devel   libpng-devel  libjpeg-devel

tar -zxf php-5.2.17.tar.gz

cd php-5.2.17

./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache/bin/apxs --disable-debug --enable-xml --with-gd  --with-gettext  --with-mysql=/usr

make

make install

cp php.ini-dist   /usr/local/lib/php.ini

( copy the sample php configuration to /usr/local/lib)

ln -s /usr/local/lib/php.ini   /etc/php.ini

Once everything completed fine , then the php binaries will be installed in the prefix directory

You can verify the installation using

/usr/local/php5/bin/php -v
PHP 5.2.17 (cli) (built: Jun  8 2011 04:45:05)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

##### Test and confirm web server is able to load a php pages #####

1)  Confirm php module is added to apache

# grep php /usr/local/apache/conf/httpd.conf

LoadModule php5_module        modules/libphp5.so

2) Find the DocumentRoot of  your  apache and create a test php file

grep DocumentRoot /usr/local/apache/conf/httpd.conf
DocumentRoot “/usr/local/apache/htdocs”

vi /usr/local/apache/htdocs/index.php
<?
phpinfo();
?>

3) Now we need to add the following two directives to apache conf

# vi /usr/local/apache/conf/httpd.conf

( search for ” AddType” and add the following in the next line , The AddType directive maps the given filename extensions onto the specified content type  )

AddType application/x-httpd-php  .php

(Search for DirectoryIndex and replace the line with following )

DirectoryIndex index.html  index.php

Restart apache and check the webserver is loading this index.php file ,

http://192.168.1.2/index.php

Its should display the phpinfo page as follows

Hope this will helps you to setup a Lamp server  🙂  , If you are looking for a well tuned webserver then check this : Apache performance tuning