How To Run PHP 4 and 5 in Ubuntu Without CGI
June 21, 2007 – 6:50 pmWhen we chose Symfony to implement ThemBid.com, PHP 5 was needed but we only had PHP 4 installed in our Ubuntu hosting servers. We couldn’t just migrate everyone to PHP 5 since some of client’s applications were incompatible with PHP 5. Some tutorials were found online explaining how to run PHP 4 and PHP 5 simultaneously such as this and this but they all used CGI. As you probably know, CGI is not scalable and we needed to scale in PHP4 and PHP5 since we needed to server millions of hits in both configurations. The following are additional the requirements we had:
- Run Apache
- Use mod_php for both PHP versions.
- Run eAccelerator with both PHP versions.
- Use as many Ubuntu packages as possible to ease maintenance issues and easily deploy on multiple servers.
- Use Ubuntu 6.06.1 LTS
The solution we came up with was to run Apache 2 with PHP 5 and run Apache 1 with PHP 4 on separate IPs. Ubuntu comes already with these packages. The only package we had to compile was eAccelerator. The following lists the steps taken to get this setup:
Apache 2 with PHP 5
- apt-get install apache2 libapache2-mod-php5 php5 php5-cli php5-curl php5-gd php5-mysql php5-dev make php5-mcrypt php5-imap
- vi /etc/php5/cli/php.ini and uncomment extension=mysql.so
- vi /etc/apache2/ports.conf and put Listen Your.IP.Goes.Here:80
- a2enmod expires
- vi /etc/apache2/conf.d/hosting
<VirtualHost *>
DocumentRoot /home/httpd/mainpage
ServerName mainpage.com
ServerAlias www.mainpage.com
Options Includes FollowSymlinks
AddType application/x-httpd-php .php
DirectoryIndex index.php index.html index.htm
</VirtualHost># Cache images and javascripts
ExpiresActive on
ExpiresByType image/gif “access plus 1 week”
ExpiresByType image/jpeg “access plus 1 week”
ExpiresByType image/png “access plus 1 week”
ExpiresByType image/x-icon “access plus 4 week”
ExpiresByType application/x-javascript “access plus 4 week”
ExpiresByType application/x-shockwave-flash “access plus 4 week” - cd /usr/local/src
- wget http://bart.eaccelerator.net/source/0.9.5/eaccelerator-0.9.5.tar.bz2
- tar xjvf eaccelerator-0.9.5.tar.bz2
- cd eaccelerator-0.9.5/
- phpize5
- ./configure
- make
- make install
- mkdir /var/tmp/{eaccelerator4,eaccelerator5}
- chown www-data /var/tmp/eaccelerator*
- chmod 700 /var/tmp/eaccelerator*
- vi /etc/php5/apache2/php.ini and add the following:
zend_extension=”/usr/lib/php5/20051025/eaccelerator.so”
eaccelerator.shm_size=”0″
eaccelerator.cache_dir=”/var/tmp/eaccelerator5″
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=”"
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”0″
eaccelerator.shm_prune_period=”0″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
Apache 1 with PHP 4
- apt-get install libapache-mod-php4 php4-mysql php4-gd apache-ssl apache-common libzzip-0-12 php4-common php4-dev apache
- dpkg-reconfigure apache and uncheck mod_userdir and check mod_php4 and cancel on hostname
- vi /etc/apache/httpd.conf and make sure to add this
Listen Your.SECONDIP.Goes.Here:80
NameVirtualHost *# Cache images and javascripts
ExpiresActive on
ExpiresByType image/gif “access plus 1 week”
ExpiresByType image/jpeg “access plus 1 week”
ExpiresByType image/png “access plus 1 week”
ExpiresByType image/x-icon “access plus 4 week”
ExpiresByType application/x-javascript “access plus 4 week”
ExpiresByType application/x-shockwave-flash “access plus 4 week”Remove the following
<IfModule mod_alias.c>
Alias /icons/ /usr/share/apache/icons/
<Directory /usr/share/apache/icons>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>Alias /images/ /usr/share/images/<Directory /usr/share/images>
Options MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</IfModule>
<IfModule mod_alias.c>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory /usr/lib/cgi-bin/>
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
</IfModule>Change
<Directory />
Options SymLinksIfOwnerMatch
AllowOverride All
</Directory>
ServerSignature Off
ServerTokens Prod - cd /usr/local/src
- rm -rf eaccelerator-0.9.5
- tar xjvf eaccelerator-0.9.5.tar.bz2
- cd eaccelerator-0.9.5/
- phpize4
- ./configure –with-php-config=/usr/bin/php-config4
- make
- make install
- vi /etc/php4/apache/php.ini and add the following:
zend_extension=”/usr/lib/php4/20050606/eaccelerator.so”
eaccelerator.shm_size=”0″
eaccelerator.cache_dir=”/var/tmp/eaccelerator4″
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=”"
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”0″
eaccelerator.shm_prune_period=”0″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
Isaac Saldana
6 Responses to “How To Run PHP 4 and 5 in Ubuntu Without CGI”
Really interesting stuff! Is MySql simple enough to integrate with this approach?
By Jojodi on Jun 21, 2007
Yes MySQL already works fine with this setup.
By isaldana on Jun 21, 2007
Couldn’t you have accomplished what you neded with XAMPP?
http://www.apachefriends.org/en/xampp-linux.html
It looks like it supports all you need plus more. It can be installed in 10 minutes, which includs the following
Apache 2.2.4, MySQL 5.0.41, PHP 5.2.2 & 4.4.7 & PEAR + SQLite 2.8.17/3.3.17 + multibyte (mbstring) support, Perl 5.8.7, ProFTPD 1.3.0a, phpMyAdmin 2.10.1, OpenSSL 0.9.8e, GD 2.0.1, Freetype2 2.1.7, libjpeg 6b, libpng 1.2.12, gdbm 1.8.0, zlib 1.2.3, expat 1.2, Sablotron 1.0, libxml 2.4.26, Ming 0.3, Webalizer 2.01, pdf class 009e, ncurses 5.8, mod_perl 2.0.2, FreeTDS 0.63, gettext 0.11.5, IMAP C-Client 2004e, OpenLDAP (client) 2.3.11, mcrypt 2.5.7, mhash 0.8.18, eAccelerator 0.9.5.1, cURL 7.13.1, libxslt 1.1.8, phpSQLiteAdmin 0.2, libapreq 2.07, FPDF 1.53, XAMPP Control Panel 0.6
By Abe on Jun 22, 2007
With XAMPP you can only run an instance of PHP at a time such as /opt/lampp/lampp php4 or /opt/lampp/lampp php5. Here we needed to run both simultaneously. Another requirement we had was to use as many Ubuntu packages as possible to ease maintenance issues and easily deploy on multiple servers.
By isaldana on Jun 22, 2007