Howto Install the Suhosin Extension For a FastCGI-Based PHP Install

I am running two versions of PHP on my Ubuntu 10.04 Lucid servers now.  The one from the repositories is PHP 5.3.2 and is installed as an Apache module.  The other one is PHP 5.2.14 and was compiled manually and setup as a FastCGI method.

To see how to setup two versions of PHP on Ubuntu Lucid 10.04, click here to see my previous article.

Now, the information below is tailored towards my specific need to install the Suhosin extension (not just the Suhosin patch – because that was done in the previous article – but the Suhosin extension which allows for most of the functionality to be used).

One thing I continued to have a problem with when I was creating the Suhosin extension from source – was that it was pulling all the source libraries from the PHP 5.3.2 version out of the /usr directory.  This required a few hours of work to get this fixed.

First of all, you need to download the Suhosin extension.  Go here and download the source file.

After you download it, I would recommend moving the file to where your PHP 5.2.14 install is located at.  Based on my previous article, mine is installed in /opt/php5.2.14.

sudo mv suhosin* /opt/php5.2.14
cd /opt/php5.2.14

Now that you have it moved and changed your directory, you need to untar the file:

tar xvf suhosin*
cd suhosin*

OK, that is now done and you’ve changed the directory to the folder where the Suhosin files were unpacked. The next step is to “phpize” the install. If you just run “phpize”, you are going to pull in the data from your PHP 5.3.2 install – you DO NOT want that. So, you need to find where “phpize” is in your PHP 5.2.14 install:

sudo find /opt -name “phpize”

Mine is located at /opt/php5.2.14/bin/phpize. So, now while you are in the Suhosin source directory, run that command:

sudo /opt/php5.2.14/bin/phpize

After a few moments, you’ll be returned back to the prompt. What this file does is to create the “configure” file you need to configure Suhosin. Now, open up the configure file using any text editor.

sudo mc -e configure

Now, you need to search for a line. Now you need to search for a line that looks like this (around line 4021):

PHP_PHP_CONFIG=php-config

You now need to update this line so it runs from your PHP 5.2.14 installation, not your main installation on the server. To do this, just change the line to:

PHP_PHP_CONFIG=/opt/php5.2.14/bin/php-config

Now, save and close the file. Run the following items to make and install the file:

sudo ./configure –enable-suhosin
sudo make
sudo make install

Now your suhosin.so file should be created! Ensure you note the location of the file and move it to your extensions directory (mine is just in the /opt/php5.2.14/lib/php directory). The next step is to ensure you update your “extension_dir” to the appropriate location in your php.ini file where the extension is at. If this is already set, just ensure you move the suhosin.so file to that directory that is already set. Then add the extension. These two lines are at the bottom of my php.ini config:

extension_dir = “/opt/php5.2.14/lib/php
extension=suhosin.so

That is all! Now you can begin to make use of the Suhosin extension functions right away. Because it is loaded as FastCGI and not a module, you don’t even need to reload Apache!