I came across a situation this week where a client wanted to install Zend Optimizer on his VPS as his website needed it. But the default PHP version installed on the server was PHP 5.3 and Zend Optimizer works only with PHP versions upto 5.2. So we had two options in front of us to resolve the issue, either install 5.2 from source or advice the client to recompile his application with Zend guard loader which is the replacement for Zend Optimiser in PHP 5.3 and newer versions. (Applications compiled for Zend Optimiser won't work with Zend guard loader). As he don't wished to recompile his application, we went for the first option. That's to install PHP from source.
Some additional packages will be needed for the installation, so we will install them first :
# yum -y groupinstall "Development Tools"
# yum -y mysql-devel libtool-ltdl-devel bzip2-devel libcurl-devel libxml2-devel libmcrypt-devel curl-devel
Now download PHP package from www.php.net/downloads.php# cd /usr/local/src
# wget http://museum.php.net/php5/php-5.2.17.tar.bz2
# tar -xvzf php-5.2.17.tar.bz2
# cd php-5.2.17
Compile and install PHP
Some additional packages will be needed for the installation, so we will install them first :
# yum -y groupinstall "Development Tools"
# yum -y mysql-devel libtool-ltdl-devel bzip2-devel libcurl-devel libxml2-devel libmcrypt-devel curl-devel
Now download PHP package from www.php.net/downloads.php# cd /usr/local/src
# wget http://museum.php.net/php5/php-5.2.17.tar.bz2
# tar -xvzf php-5.2.17.tar.bz2
# cd php-5.2.17
Compile and install PHP
#./configure
--prefix=/usr/local/php_52 --enable-cgi
--with-config-file-path=/usr/local/php_52 --enable-ftp --enable-mbstring --with-openssl --enable-magic-quotes --with-zlib --with-bz2
--with-curl --with-gd --with-mcrypt --with-mysql --enable-zip
--enable-libxml --with-gettext --with-gmp --with-iconv
# make clean
# make
# make install
Now we need to make apache to detect this installation. As its Kloxo we need to perform some additional tasks/modifications. First create a script,
# cd /var/www/cgi-bin
# vi php52-cgi
Add the below code :
#!/bin/sh
PHPRC="/usr/local/php_52/"
export PHPRC
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec /usr/local/php_52/bin/php-cgi
Then save the file.# chmod +x php52-cgi
# cd ~
# ln -s /usr/local/php_52/bin/php-cgi /usr/local/bin/php52
Now we need to modify apache config
# cp -prf /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_org
# echo 'Enable PHP5.2 Handlers' >> /etc/httpd/conf/httpd.conf
# echo 'ScriptAlias /php52-cgi /var/www/cgi-bin/php52-cgi' >> /etc/httpd/conf/httpd.conf
# echo 'Action application/x-httpd-php52 /php52-cgi' >> /etc/httpd/conf/httpd.conf
But when we runs fixweb script, the additions to httpd.conf will get deleted. So, we need to modify fixweb script
# cp /script/fixweb /script/fixweb.orig
# vi fixweb
Add the below code :
#!/bin/sh
. /script/fix.inc
. /script/directory
lphp.exe ../bin/fix/fixweb.php $*
#Reinstate php5.2 handlersecho 'Enable PHP5.2 Handlers' >> /etc/httpd/conf/httpd.conf
# echo 'ScriptAlias /php52-cgi /var/www/cgi-bin/php52-cgi' >> /etc/httpd/conf/httpd.conf
# echo 'Action application/x-httpd-php52 /php52-cgi' >> /etc/httpd/conf/httpd.conf
service httpd restart
Then save the file.
# mv fixweb /script/fixweb
# chmod 700 /script/fixweb
Now add the following code in your website's .htaccess file :
<FilesMatch "\.php">
SetHandler application/x-httpd-php52
</FilesMatch>
That's all.. :)
# make clean
# make
# make install
Now we need to make apache to detect this installation. As its Kloxo we need to perform some additional tasks/modifications. First create a script,
# cd /var/www/cgi-bin
# vi php52-cgi
Add the below code :
#!/bin/sh
PHPRC="/usr/local/php_52/"
export PHPRC
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec /usr/local/php_52/bin/php-cgi
Then save the file.# chmod +x php52-cgi
# cd ~
# ln -s /usr/local/php_52/bin/php-cgi /usr/local/bin/php52
Now we need to modify apache config
# cp -prf /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_org
# echo 'Enable PHP5.2 Handlers' >> /etc/httpd/conf/httpd.conf
# echo 'ScriptAlias /php52-cgi /var/www/cgi-bin/php52-cgi' >> /etc/httpd/conf/httpd.conf
# echo 'Action application/x-httpd-php52 /php52-cgi' >> /etc/httpd/conf/httpd.conf
But when we runs fixweb script, the additions to httpd.conf will get deleted. So, we need to modify fixweb script
# cp /script/fixweb /script/fixweb.orig
# vi fixweb
Add the below code :
#!/bin/sh
. /script/fix.inc
. /script/directory
lphp.exe ../bin/fix/fixweb.php $*
#Reinstate php5.2 handlersecho 'Enable PHP5.2 Handlers' >> /etc/httpd/conf/httpd.conf
# echo 'ScriptAlias /php52-cgi /var/www/cgi-bin/php52-cgi' >> /etc/httpd/conf/httpd.conf
# echo 'Action application/x-httpd-php52 /php52-cgi' >> /etc/httpd/conf/httpd.conf
service httpd restart
Then save the file.
# mv fixweb /script/fixweb
# chmod 700 /script/fixweb
Now add the following code in your website's .htaccess file :
<FilesMatch "\.php">
SetHandler application/x-httpd-php52
</FilesMatch>
That's all.. :)
0 comments: