Installing PHP4 and PHP5 concurrently on Ubuntu and Apache2

I came across ezPublish as a possible nice CMS for use in a couple projects I'm working on, but stumbled when it required PHP4. Rather than downgrading my full Apache2 instance just to test the app, I decided to get both 4 and 5 working on my Ubuntu laptop. Seem to be various ways to do it, but the best (er, first) I found was Windows-specific, so in the interests of fair-n-balanced, here's how I did it on my machine.Since you can only have one version enabled as a module, the other must be used through CGI. Ubuntu makes it stupidly simple to do this: Both versions of PHP are distributed as CLI (command line) and CGI binaries, in addition to the apache module versions (which the package manager restricts to just one).So to ensure you have everything, execute:<br />$ wajig installrs php4-cgi libapache2-mod-php5<br />... If by some chance you don't yet have wajig, get with it! $ sudo apt-get install wajigNext, to enable me to have access either version easily, I added an entry to /etc/hosts:<br />127.0.0.2        localhost4.local localhost4<br />Then I went into /etc/apache2/sites-available and copied 000-default to 001-localhost4.conf. I changed the NameVirtualHost and VirtualHost settings to use localhost4:80 and added the following lines:<br />Action php4-script /cgi-bin/php4<br />AddHandler php4-script .php<br />Then execute:<br />$ sudo a2ensite 001-localhost4.conf<br />$ sudo apache2ctl restart<br />Now you should be able to access your site content via http://localhost and http://localhost4.To confirm that it's working, if you don't already have one, you can view the php config thusly:<br />$ echo '&lt;?php phpinfo(); ?&gt;' &gt; /tmp/phpinfo.php<br />$ sudo mv /tmp/phpinfo.php /var/www/phpinfo.php<br />Voila!

Comments

One additional step I needed

One additional step I needed to take was install apache's actions module like so:

$ sudo a2enmod actions

Then after restarting apache, everything worked as expected. Thanks!

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <pre>, <shell>, <c>, <drupal6>, <java>, <javascript>, <objc>, <perl>, <php>, <python>, <rails>, <ruby>, <sql>, <xmlcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.