WARNING: The data on the server were damaged due to the fire in Hosting.UA DC. All files will be restored shortly.
Introduction
As you know,
CentOS5 is being shipped with
PHP5 which, especially, is being installed in ISAPI mode and thus makes the installation of additional PHP4 modules not available. The solution is to run PHP4 in CGI mode. So, to get it working CGI mode we have to:
- download latest PHP4 source from here
- compile it and place somewhere
- ask Apache 2.2 to use just compiled php binaries as a PHP-processor on particular virtual hosts.
Well, I did so and was very upset - PHP wasn't working as expected. Problems with UTF-8 encoding, unexpected sigfaults and other staff made this approach useless.
Fortunately, I found that the issue is already solved by
LabCoding team, here is
the article. Anyway, there was one major thing which wasn't satisfying me. Their package is being installed into the standard OS folders and was causing conflicts with some of my existing files. So, I decided to rebuild the PHP4 RPM packages to make PHP4 being installed into /opt/php4 directory and thus to make it separated from the entire filesystem.
How does it work?
Package
php4-4.4.8-LAB4 installs
php4 binaries into
opt/php4/bin folder. Also, other files are being installed into
/opt/php4/etc/,
/opt/php4/lib/,
/opt/php4/share/ folders. Extensions are being installed into
/opt/php4/lib/php4 directory and their configurations - into
/opt/php4/etc/php.d.
To get PHP4 working we have to set up a CGI handler set to process *.php files using
/opt/php4/bin/php4-cgi binary.
Installation and Configuration
- Configure YUM installer by creating file /etc/yum.repos.d/conforge.repo with the following content:
[conforge]
name=Conforge package for CentOS $releasever - $basearch
baseurl=http://repo.conforge.com/conforge/CentOS/$releasever/$basearch
enabled=1
gpgcheck=0
More info about Conforge repository is available
here.
~# yum install php4 php4-pear php4-mysql
- Use the following command in case you need to install all available extensions:
~# yum install php4*
- Configure Apache HTTPD. We assume PHP4 will setup for particular VirtualHost so in its block (the one surrounded with <VirtualHost></VirtualHost> directives) place these instructions:
ScriptAlias /php-bin/ /opt/php4/bin/
SetEnv PHPRC "/opt/php4/bin"
Action php4-script "/php-bin/php4-cgi"
AddHandler php4-script .php
NOTE: In case you will do that for global server then you will turn off PHP5 support at all.
- Cyrillic users would probably like to add the following in /etc/httpd/conf/httpd.conf:
AddDefaultCharset windows-1251
- NOTE: Actual build of PHP4 is not able to run if SuExec is enabled for particular virtual host. You should disable that feature otherwise all you'll see is just white screen instead of webpage.
- Reload HTTPD daemon and yo will get your PHP4 installation working:
~# /etc/init.d/httpd reload