Activities

December 2012
M T W T F S S
« Nov   Jan »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Setting up mulitple LAMP environment or Custom Apache-PHP installation from source

This week one of php dev. needs to setup two php version runs on his computer through he assigned to work both on older and newer version of php framework. Newer framework requires php 5.3 installed and we can not assign new system for this requirement.

Existing environment are
OS : CentOS 5.5
PHP : 5.2.17
MySQL : 5.0.1

Here we go,

a. Installing Apache webserver

We need 3 packages

1. Apache HTTP webserver
2. Apache Runtime Library (APR)
3. Apache runtime utility.

Download the latest Apache, APR and APR-Util source file from Apache.org website.

 [root@web01]#cd /home/installation
[root@web01]#wget http://apache.techartifact.com/mirror//httpd/httpd-2.4.3.tar.gz
[root@web01]#wget http://apache.techartifact.com/mirror//apr/apr-1.4.6.tar.gz
[root@web01]#wget http://apache.techartifact.com/mirror//apr/apr-util-1.5.1.tar.gz
[root@web01]#tar -zxvf httpd-2.4.3.tar.gz
[root@web01]#tar -zxvf apr-1.4.6.tar.gz
[root@web01]#tar -zxvf apr-util-1.5.1.tar.gz
[root@web01]#cp -r apr-1.4.6 httpd-2.4.3/srclib/apr
[root@web01]#cp -r apr-util-1.5.1 httpd-2.4.3/srclib/apr-util
[root@web01]#mkdir -p /usr/local/apr-httpd/ /usr/local/apr-util-httpd/ /usr/local/apache2
[root@web01]#cd httpd-2.4.3/srclib/apr
[root@web01]#pwd
/home/installation/httpd-2.4.3/srclib/apr
[root@web01]#./configure --prefix=/usr/local/apr-httpd/
[root@web01]#make && make install
[root@web01]#cd /home/installation/httpd-2.4.3/srclib/apr-util
[root@web01]#./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd/
[root@web01]#make && make install
[root@web01]#cd /home/installation/httpd-2.4.3
[root@web01]#./configure --with-apr=/usr/local/apr-httpd/  --with-apr-util=/usr/local/apr-util-httpd/  -prefix=/usr/local/apache2 --enable-mods-shared=most --enable-rewrite=shared --enable-speling=shared    --enable-ssl=shared --enable-so  --enable-cgi=shared  --enable-info=shared   --enable-usertrack=shared  --enable-deflate=shared  --enable-mime-magic=shared
[root@web01]#make & make install

Wholla !! you have installed Apache http server. Pls note down Apache installation folder is “/usr/local/apache2” and created two other folder for APR. This Apache have DSO support and complied with mostly used modules which required for php hosting. Just move to installation folder and check the folder structure.

My next step is to adjust the http.conf files to run the same php files used for earlier php. So I uses same documentroot on new Apache ie “/home/user/public_html“.

We need following modifications,

a. Create new network adapter and set IP alias for this new Apache on this desktop.
b. Old Apache : Modify the Apache to listen ONLY ON desktop IP ( Listen 192.168.0.134:80)
c. New Apache : Modify the Apache config file to listen only on new IP alias (Listen 192.168.0.29)
d. New Apache : Change the DocumentRoot, Directory and set AllowOveride All which will be using “home/user/public_html” in httpd.conf
d. New Apache : Edit /usr/local/apache2/conf/http.conf and set Apache User and Group same on old apace setting.

Now we need to restart both HTTP server

[root@rc-web01 apr]# /usr/local/apache2/bin/apachectl stop
[root@rc-web01 apr]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@rc-web01 apr]# /usr/local/apache2/bin/apachectl start
[root@rc-web01 apr]# netstat -nlp | grep ":80"
tcp        0      0 192.168.0.29:80             0.0.0.0:*                   LISTEN      10735/httpd
tcp        0      0 192.168.0.134:80            0.0.0.0:*                   LISTEN      10722/httpd
[root@rc-133 apr]#

b. Installing PHP 5.3 version

Download the PHP5.3 source from php.net

 [root@rc-web01]#tar -zxvf php-5.3.4.tar.gz
 [root@rc-web01]#cd /home/installation/php-5.3.4
 [root@rc-web01]#switch to php installation folder
 [root@rc-web01]#mkdir -p /usr/local/php53
 [root@rc-web01]#mkdir -p /usr/local/php53/bin /usr/local/php53/libexec /usr/local/php53/share /usr/local/php53/etc /usr/local/php53/lib /usr/local/php53/include    
 [root@rc-web01]#./configure --prefix=/usr/local/php53 --with-apxs2=/usr/local/apache2/bin/apxs  --bindir=/usr/local/php53/bin  --sbindir=/usr/local/php53/bin --libexecdir=/usr/local/php53/libexec --datadir=/usr/local/php53/share --sysconfdir=/usr/local/php53/etc --libdir=/usr/local/php53/lib --includedir=/usr/local/php53/include --with-xsl --with-mysql --with-config-file-scan-dir=/usr/local/php53/php.d  --exec-prefix==/usr/local/php53 --with-config-file-path==/usr/local/php53/etc --with-bz2 --with-curl --with-exec-dir=/usr/local/php53/bin --with-png --with-zlib --with-pear=/usr/share/pear --with-zml --with-gd --with-libxml=/usr/lib --enable-calendar --with-openssl-dir=/usr/local/ssl --with-bcmath --with-mysqli --enable-soap -with-jpeg --enable-sockets --enable-mbstring --enable-shared --with-jpeg-dir=/usr/local --with-freetype-dir=/usr/local/lib --with-mcrypt=/usr/local/bin/mcrypt -enable-pdo --with-pdo-sqlite  --with-pdo-mysql=shared
 [root@rc-web01]#make && make install

You will see the output as shown below

Now you need to add few lines in /usr/local/apache2/conf/httpd.conf

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

Then modify the line index.php in DirectoryIndex. It will looks like as below,

 [root@web01 php-5.3.4]# cat  /usr/local/apache2/conf/httpd.conf  | grep -E " php|httpd-php|DirectoryIndex"
LoadModule php5_module        modules/libphp5.so
# DirectoryIndex: sets the file that Apache will serve if a directory
 DirectoryIndex index.html index.php
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
[root@web01 php-5.3.4]#

Now it’s the turn to restart the web server.

[root@rc-web01 apr]# /usr/local/apache2/bin/apachectl stop
 [root@rc-web01 apr]# /usr/local/apache2/bin/apachectl start

Hurry !!! you will get the sample phpinfo page look likes as shown below if everything went fine.

Sit back relax !!! Go for a Coffee if possible :-)

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>