How to compile php 5.2 and run using fastcgi on CentOS 5.7

Step-1: Install required dev packages
#yum install httpd-devel libtool apr-devel aprgcc libxml2-devel bzip2-devel zlib-devel \
    curl-devel libmcrypt-devel libjpeg-devel \
    libpng-devel gd-devel mysql-devel



Step-2: Download php5.2 source and install
#wget http://cn.php.net/get/php-5.2.17.tar.bz2/from/this/mirror
#tar -xjf php-5.2.17.tar.bz2
#cd php-5.2.17
#./configure --prefix=/usr/local/php52 --with-config-file-path=/etc/php52 --with-config-file-scan-dir=/etc/php52/php.d --with-libdir=lib64 --enable-force-cgi-redirect --enable-fastcgi --with-bz2 --with-curl=/usr/local/lib --with-gd --with-gettext --with-jpeg-dir=/usr/local/lib --with-freetype-dir=/usr/local/lib --with-kerberos --with-mcrypt --with-mhash --with-mime-magic --with-mysql --with-mysqli --with-pcre-regex=/usr --with-pdo-mysql=shared --with-pdo-sqlite=shared --with-pear=/usr/local/lib/php --with-png-dir=/usr/local/lib --with-pspell --with-sqlite=shared --with-tidy --with-ttf --with-xmlrpc --with-xsl --with-zlib --with-zlib-dir=/usr/local/lib --with-openssl --with-iconv --with-libdir=lib64 --enable-bcmath --enable-calendar --enable-exif --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-magic-quotes --enable-soap --enable-sockets --enable-mbstring --enable-zip --enable-wddx

#make
#make install
#mkdir /etc/php52
#cp php.ini-recommended /etc/php52/php.in

Step-3: Install Mod-FastCGI
# wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz

Untar tar ball, type:
# tar -zxvf mod_fastcgi-current.tar.gz
# cd mod_fastcgi-2.4.6/

Make a copy of Makefile.AP2, enter:
# cp Makefile.AP2 Makefile

Compile and install mod_fastcgi for 32 bit system, enter:
# make top_dir=/usr/lib/httpd
# make install top_dir=/usr/lib/httpd

Compile and install mod_fastcgi for 64 bit system, enter:
# make top_dir=/usr/lib64/httpd
# make install top_dir=/usr/lib64/httpd

Sample output:

make install top_dir=/usr/lib64/httpd
make[1]: Entering directory `/tmp/mod_fastcgi-2.4.6'
/usr/lib64/apr-1/build/libtool –silent –mode=install cp mod_fastcgi.la /usr/lib64/httpd/modules/
make[1]: Leaving directory `/tmp/mod_fastcgi-2.4.6'
Configure mod_fastcgi
#cd /var/www/cgi-bin
#vi php.fcgi and add the followings:
####################################
#!/bin/bash
# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x
# Tested under Red Hat Enterprise Linux / CentOS 5.x
### Set PATH ###
PHP_CGI=/usr/local/php52/bin/php-cgi
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI
##################################



Open /etc/httpd/conf.d/mod_fastcgi.conf file
# vi /etc/httpd/conf.d/mod_fastcgi.conf

Add an entry to it like this:
LoadModule fastcgi_module modules/mod_fastcgi.so


Save and close the file. Restart httpd, enter:
# service httpd restart

Step-4: Setup your virtualhost to use fastcgi for processing php
#vi /etc/httpd/conf/httpd.conf

        ServerAdmin webmaster@example.com
        DocumentRoot "/var/www/php52"
        ServerName example.com
        ServerAlias www.example.com
        ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

       
                Options -Indexes FollowSymLinks +ExecCGI
                AllowOverride AuthConfig FileInfo
                AddHandler php5-fastcgi .php
                Action php5-fastcgi /cgi-bin/php.fcgi
                Order allow,deny
                Allow from all
       



#service httpd restart