Module and CGI

Installing PHP 5 as a CGI is a quick way to get up and running without sacrificing PHP 4. This section describes two techniques for making PHP 5 parse your code, instead of PHP 4.

Remember that the CGI version of PHP has a few limitations compared to the Apache module version. It cannot hook into HTTP Basic Authentication, nor can you read and write internal Apache values using functions such as apache_note( ).

One option is to enable PHP 5 on a directory-by-directory basis. This lets the PHP 4 module handle scripts by default, but lets you slowly release PHP 5 code when it’s ready.

The second alternative is to enable PHP 5 for all files but on another port. By default, Apache listens for requests on port 80, so normal requests are still handled as usual. However, whenever a request is made to your site on port 8080, Apache now hands the script off to PHP 5. With this setup, you can easily get a complete overview of your PHP 5 compatibility without sacrificing PHP 4 support.

This process breaks down into two main parts: configuring PHP 5 and configuring Apache. The PHP 5 configuration is identical for either Apache setup, so you can easily switch between the two.

Configuring PHP 5 as a CGI

Installing PHP 5 as a CGI requires four additional steps beyond your normal configuration:

  1. Remove --with-apxs .

  2. Add --enable-force-cgi-redirect .

  3. Add --prefix=/usr/local/php5 .

  4. Customize php.ini.

PHP defaults to a CGI installation, but it won’t build it when you specify a web server ...

Get Upgrading to PHP 5 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.