JOMYUT.NET Just a normal guy in binary world

11Apr/11Off

Install PHP 5.2/5.3 in the same machine

This is solution for DirectAdmin machine owner who would like to use both version of PHP5 in their system. First, you may see reference topic here and here. To install both PHP versions with custombuild, you are require to trick the DirectAdmin with PHP6 configuration because DirectAdmin itself doesn't support both PHP5 working at the same time.

One solution to choice

In the solution I provided, I make PHP5.3 as default compiler running as CLI. and PHP 5.2 can be optional used with .htaccess level configuration. (running by suPHP)

  1. Change the custombuild build script to version 1.2
    cd /usr/local/directadmin/custombuild/
    ./build set custombuild 1.2
  2. Change automatic download new versions.txt to be No.
    ./build set autover no
    Later, explained.
  3. Build update and copy PHP5 configuration to PHP6 custombuild path
    ./build update
    mkdir -p custom/suphp
    cp -pf configure/suphp/configure.php5 custom/suphp/configure.php6
  4. For me, I implement PHP5.3 running as CLI and PHP5.2 as CGI by suPHP. This is difference from referenced topic
    perl -pi -e 's/php5\:/phprep\:/' versions.txt
    perl -pi -e 's/php6/php5/' versions.txt
    perl -pi -e 's/phprep/php6/' versions.txt
  5. Set build options
    ./build set php5_ver 5.3
    ./build set php6_cgi yes
    ./build set php6_cli no
    ./build set php5_cgi no
    ./build set php5_cli yes

    Note that php6 is a configuration for PHP 5.2 and PHP5 is a configuration for PHP 5.3 and running as default engine.
  6. Build both PHP versions.
    ./build php n
  7. Change path of the PHP 5.2 package

Now, below is a configuration for PHP 5.2 based website. you have to put these code in .htaccess to root of public_html directory

<FilesMatch "\.php$">
AddHandler x-httpd-php6 .php
</FilesMatch>

if you don't like to use x-httpd-php6, you may change to x-httpd-php52 or somewhat you want. but you have to config below files

perl -pi -e 's/x-httpd-php6/x-httpd-php52/' /usr/local/suphp/etc/suphp.conf
perl -pi -e 's/x-httpd-php6/x-httpd-php52/' /etc/httpd/conf/extra/httpd-suphp.conf

Now, you can use website with PHP 5.2 and PHP 5.3 upon .htaccess configuration.