HomePage » WebServer » PHP » PHPMixedVersion


Running php4 and php5 on the same apache


At times, client might want to have both ptp4 and php5 running on the same apache. I guess they are just too lazy to fix their code so they all run in php5. The basic concept is to have one of the version installed as Apache DSO library, the other as CGI. Below is an example where the client has php4 installed as DSO on his Apache, and he wants to add php5 support -

First php4 as primary
In httpd.conf:
LoadModule php4_module        modules/libphp4.so
AddType application/x-httpd-php .php .phtml


Then adding php5
First compile php5. In the configure option, do not include the --with-apxs option. This is required for php to build the php-cgi binary which will be used later on. My configure options:
./configure --prefix=/usr/local/php5 \
--with-libxml-dir=/usr/local --with-bz2 \
--with-curl --with-dom --with-dom-xslt \
--enable-ftp --with-gd --with-gettext \
--with-gmp --with-mime-magic --with-ncurses \
--with-pcre-regex --enable-posix --with-pspell \
--with-readline --enable-session --enable-sockets \
--enable-sysvsem --enable-sysvshm --with-xmlrpc \
--with-zlib --with-jpeg-dir=/usr --with-png-dir=/usr \
--with-dom-xslt --with-mysql \
--enable-force-cgi-redirect --enable-discard-path

After this is installed, one should find the php-cgi binary in $PREFIX/bin. Now onto apache configuration:
This will enable php5 in certain directory in a certain virtualhost:
<VirtualHost 1.2.3.4:80>
ScriptAlias /php5-bin /usr/local/php5/bin/
<Directory /usr/local/php5/bin/>
		Options +ExecCGI +FollowSymLinks
		AllowOverride None
</Directory>

<Location /php5>
		Action php5-cgi /php5-bin/php-cgi
		AddHandler php5-cgi .php .php5
</Location>
</VirtualHost>



Alternatively, php5 can be enabled globally by file extension:
ScriptAlias /php5-cgi /usr/lib/php5/bin/php-cgi
Action php5-cgi /php5-cgi
AddHandler php5-cgi .php5 
Comments [Hide comments/form]
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki