Apache2 with PHP5 CGI and PHP4 module on OS X

Looking at the configuration now looks like it was a job at ease; but it took me some hours to work properly. PHP is now working in two versions in parallel on Apache2 on OS X 10.3.3. I will show you the configurations for the compilation first. Firstly, there is the configuration for PHP 4.3.4:

#:~/src/php-4.3.4 urs$ ./configure \\
--disable-cgi \\
--disable-pdo \\
--enable-force-cgi-redirect \\
--prefix=/usr/local/php \\
--with-zlib \\
--with-iconv=/sw/ \\
--without-bundle-libxml \\
--with-dom=/sw/ \\
--with-libxml-dir=/sw/ \\
--with-xsl=/sw/ \\
--disable-pear \\
--with-gd \\
--with-freetype-dir=/sw/lib/freetype2/ \\
--with-jpeg-dir=/sw/ \\
--with-png-dir=/sw/ \\
--enable-sockets \\
--enable-pcntl \\
--enable-shmop \\
--enable-sysvshm \\
--enable-sysvsem \\
--with-mysql=/usr/local/mysql/ \\
--enable-debug \\
--with-apxs2=/usr/local/apache2/bin/apxs \\
--with-config-file-path=/usr/local/php \\
--with-config-file=/usr/local/php/php.ini

As below, this is what you can type to get PHP 5.0.0 RC1:

#:~/src/php-5.0.0RC1 urs$ ./configure \\
--enable-force-cgi-redirect \\
--prefix=/usr/local/php5-cgi \\
--with-zlib \\
--with-iconv=/sw/ \\
--without-bundle-libxml \\
--with-dom=/sw/ \\
--with-libxml-dir=/sw/ \\
--with-xsl=/sw/ \\
--disable-pear \\
--with-gd \\
--with-freetype-dir=/sw/lib/freetype2/ \\
--with-jpeg-dir=/sw/ \\
--with-png-dir=/sw/ \\
--with-mysql=/usr/local/mysql/ \\
--enable-debug \\
--with-config-file-path=/usr/local/php5-cgi \\
--with-config-file=/usr/local/php5-cgi/php.ini

I have chose specific configuration paths for each version. As far as I can see, you need to give the path and the filename as well. Especially for the CGI version, you should specify the option –enable-force-cgi-redirect.

Now the tricky part was to get a working configuration for the virtual hosts. The idea behind is to have a PHP 4 module installed as default and a per-virtual-host-configuration for other versions of PHP; that might be PHP 5 or 3. So on port 86 php scripts will be processed by PHP 5.0.0 RC1.


Listen 86
<VirtualHost _default_:86>
ServerName localhost

ScriptAlias /php5 /usr/local/php5-cgi/bin/
<Directory /usr/local/php5-cgi/bin/>
Options +ExecCGI +FollowSymLinks
AllowOverride None
</Directory>

DocumentRoot /Library/Webserver/Documents/project-a
<Directory /Library/Webserver/Documents/project-a>
DirectoryIndex index.php
Options Includes Indexes FollowSymLinks MultiViews
AllowOverride None Options FileInfo
Action php5-cgi /php5/php
AddHandler php5-cgi .php .php5
</Directory>

ErrorLog logs/default_86-error_log
CustomLog logs/default_86-access_log combined
</VirtualHost>

<VirtualHost *>
LoadModule php4_module modules/libphp4.so
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DocumentRoot /Library/Webserver/
<Directory /Library/Webserver/>
DirectoryIndex index.php
Options Includes Indexes FollowSymLinks MultiViews
AllowOverride None Options FileInfo
</Directory>
</VirtualHost>

I collected various links and jotted down some eventually interesting information in the (Wiki/PHP5).

Leave a Reply