Installing php5-cgi on Debian

For a long time I wanted to be able to run both PHP 4 and PHP 5 on the same server. Now I finally managed to come up with a solution that is easy to install and easy to use.

  1. Add the Debian Backports repository to your /etc/apt/sources.list
    deb http://www.backports.org/debian/ sarge-backports main contrib non-free
  2. Issue a package update: aptitude update
  3. Install PHP 5 as CGI module: aptitude install php5-cgi
  4. Configure Apache by adding the following lines to your main config file. In my case this was /etc/apache2/apache2.conf
    ScriptAlias /php5-cgi /usr/lib/cgi-bin/php5
    Action php5-cgi /php5-cgi
  5. Now find the Virtual Host you want to run on PHP 5 and simply put the following line into the <Directory> directive.
    AddHandler php5-cgi .php
    This overrides the default handler for files ending in .php which would be the normal PHP 4 module. Whit this directive it is now parsed and executed by the PHP 5 CGI binary.
  6. Reload your webserver config with
    /etc/init.d/apache2 reload

About Florian Beer

I am running my own company 42dev where I provide web application development & hosting services for my clients.

5 comments

  1. There are a few places round the Internet which attempt to explain this, but yours was the only one which worked for me, after several hours hair pulling. Thanks for a great article!

  2. Hi,

    mod_actions was not enabled in the default apache2 install (debian sid) I had. So if a restart looks like this:

    $ sudo /etc/init.d/apache2 restart
    Restarting web server: apache2Syntax error on line 20 of /etc/apache2/sites-enabled/000-default:
    Invalid command ‘Action’, perhaps misspelled or defined by a module not included in the server configuration
    failed!

    You need to run the following command:

    $ sudo a2enmod actions

  3. Thank you so so much. it is really helpful and simple.. after spent too many hours with a lot of combination, you mention the correct one with simple way..
    thanks again…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>