FreeBSD Plesk 8 – installing php5 as CGI alongside php4

If you have ever needed php5 to run along side php4, you can always compile php5 as a CGI, and let php4 remain as an apache module.

Here we’ve compiled php5 from FreeBSD’s ports, and have installed it as a CGI so that specific vhosts will run on this new php5. The installation was done on a Plesk 8 box running FreeBSD 6.x.


Compiling PHP5 (installation from FreeBSD Ports)

1) Update port tree using portsnap (use `portsnap extract` instead of update if this is the first time you’ve used portsnap). Or use classic rsync techniques.

portsnap fetch; portsnap update

2) Configure php5 and install:

cd /usr/ports/lang/php5
make config; make install

In the config, the basics should already be selected, make sure you have not selected php5 as an apache module, and keep debugging turned off unless you require this.

3) Compile the php5 extensions.

cd /usr/ports/lang/php5-extensions
make config; make install

In the config, make sure you have selected the extensions that you require. For my purposes, I’ve selected: BZ2, CTYPE, CURL, DOM, EXIF, FILTER, GD, GETTEXT, HASH, ICONV, IMAP, JSON, MCRYPT, MHASH,MYSQL, NCURSES, PCRE, PDO, PDO_SQLITE, POSIX, SESSION, SIMPLEXML, SOAP, SPL, SQLITE, TOKENIZER, XML, XMLREADER, XMLRPC, XMLWRITER, XSL, ZLIB.

4) Create the directory for your installation of php, and make sure it is owned by the proper user (the siteowner) so that suexec will be happy running binaries in this directory:

mkdir /usr/local/psa/home/vhosts/yoursite.com/httpdocs/php5-cgi
chown siteowner:psacln /usr/local/psa/home/vhosts/yoursite.com/httpdocs/php5-cgi

5) Copy the new php-cgi over to this directory (we’re naming the php-cgi binary ‘php’) and make sure to set the ownership to the siteowner, so that suexec can run this binary.

cp /usr/local/bin/php-cgi /usr/local/psa/home/vhosts/yoursite.com/httpdocs/php5-cgi/php
chown siteowner:psacln /usr/local/psa/home/vhosts/yoursite.com/httpdocs/php5-cgi/php

6) Move the recommended configuration file to the real configuration file location, edit if necessary:

mv /usr/local/etc/php.ini-recommended /usr/local/etc/php.ini

Now we add the vhost configuration and apache bits:


Add the following to your /usr/local/psa/home/vhosts/yoursite.com/conf/vhost.conf (change “yoursite.com” to your domain name or host)


ScriptAlias /php5-cgi /usr/local/psa/home/vhosts/yoursite.com/httpdocs/php5-cgi
Action application/x-httpd-php5-custom "/php5-cgi/php"

AddType application/x-httpd-php5-custom .php
AddType application/x-httpd-php5-custom .php5

Run the reconfiguration utility and restart apache:


/usr/local/psa/admin/sbin/my_apci_rst
/usr/local/psa/rc.d/httpd restart

Test out the page with a phpinfo.php script, you can create one easily from the command line, go into the httpdocs directory and run this:


echo "<?php
phpinfo();
?> " > phpinfo.php

From a browser, go to yoursite.com/phpinfo.php and see if you have the new php you just installed showing up. If you do, you have succeeded. If not, or if there are any errors, here are a few things to try:

Troubleshooting

Check the local site error_log:

/usr/local/psa/home/vhosts/yoursite.com/statistics/logs/error_log

Check the suexec log:

/usr/local/psa/apache/logs/suexec_log

Try running php from the command line:

/usr/local/bin/php -v

If you see any errors on the command line, this will result in the binary not working from Apache.

One error I ran into was this:


/usr/local/bin/php --version
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/20060613/xsl.so' - Shared object "libgpg-error.so.3" not found, required by "libexslt.so.8" in Unknown on line 0
PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Nov 26 2007 03:33:26)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

This was caused by some ports being older versions. To solve this, you must make sure that the libgpg-error and related ports are up to date, and then recompile the php5-xsl port:

recompile (from packages -P) libgpg-error and related ports:

portupgrade -rf libgpg-error-\* -P

Recompile xsl related ports, I may be recompiling too many, but this worked for me:

cd /usr/ports/textproc/libxslt
make clean; make deinstall; make install
cd /usr/ports/textproc/php5-xsl
make clean; make deinstall; make install
cd /usr/ports/textproc/php5-xml
make clean; make deinstall; make install

This solved the shared library problem, and allowed php5 to work. You shouldn’t have to recompile php after this, since this only impacts the shared libraries.

Double check your /usr/local/etc/php/extensions.ini to make sure that you have all the libraries installed that you require.

Leave a Reply

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

*