How To Harden PHP5 With Suhosin On Mandriva 2007 Spring
Author: Falko Timme
This tutorial shows how to harden PHP5 with Suhosin on a Mandriva 2007 Spring server. From the Suhosin project page: "Suhosin is an advanced protection system for PHP installations that was designed to protect servers and users from known and unknown flaws in PHP applications and the PHP core. Suhosin comes in two independent parts, that can be used separately or in combination. The first part is a small patch against the PHP core, that implements a few low-level protections against buffer overflows or format string vulnerabilities and the second part is a powerful PHP extension that implements all the other protections."
This document comes without warranty of any kind! I do not issue any guarantee that this will work for you!
1 Preliminary Note
I have tested this on a Mandriva 2007 Spring server with the IP address 192.168.0.100.
This tutorial is a bit untypical because there's nothing you need to do to install Suhosin on Mandriva 2007 Spring if you have PHP5 installed, because Mandriva's PHP5 already comes with Suhosin by default. Anyway, I think it's still worth writing this tutorial because it answers the question "What do I have to do to install Suhosin?" - nothing, if PHP5 is already installed.
2 Installing Apache2 And PHP5 (Optional)
(This chapter is optional if you already have Apache2 and PHP5 installed - to check if Suhosin is enabled in your PHP5, please skip to the next chapter.)
First, if you use Mandriva's online repository (and not the Mandriva DVD) to install packages, you should update your packages database:
If you don't have Apache2 and PHP5 installed on your server, install it now:
urpmi apache-mod_php libphp5_common5
A lot o other packages will be installed as dependencies together with these two packages, as you can see in the output:
[[email protected] ~]# urpmi apache-mod_php libphp5_common5
To satisfy dependencies, the following packages are going to be installed:
Proceed with the installation of the 27 packages? (6 MB) (Y/n)
As you see, the package php-suhosin gets installed automatically, so your PHP5 will be hardened by Suhosin by default.
Then start Apache2:
You now have a PHP5 with basic functionality on your server; if you need special PHP5 modules, you can search for them like this:
urpmi --fuzzy php
From the output, pick the modules you need, install them like this and restart Apache2:
urpmi php-bz2 php-calendar php-ctype php-curl php-dio php-dom php-eaccelerator php-enchant php-esmtp php-event php-exif php-fam php-ffmpeg php-fileinfo php-filepro php-ftp php-gd php-gettext php-gmp php-iconv php-id3 php-idn php-imap php-imlib2 php-mailparse php-mbstring php-mcache php-mcrypt php-mhash php-ming php-mysql php-mysqli php-ncurses php-newt php-odbc php-oggvorbis php-pam_auth php-pcntl php-pcre php-pear-Net_IDNA php-posix php-pspell php-readline php-recode php-session php-shmop php-simplexml php-snmp php-soap php-sockets php-sqlite php-ssh2 php-sysvmsg php-sysvsem php-sysvshm php-tclink php-tcpwrap php-tidy php-xml php-xmlrpc php-zip php5-ini
3 Getting Details About Your PHP5 Installation
Unless you have already created virtual hosts in your Apache installation, the document root of the default web site is /var/www/html. We will now create a small PHP file (info.php) in that directory (if you have created virtual hosts, place it in any of the virtual hosts that has PHP enabled) and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.
<?php phpinfo(); ?>
Now we call that file in a browser (e.g. http://192.168.0.100/info.php):
As you see, our PHP version is 5.2.1.
If everything went ok, you should now see Suhosin mentioned in two places on the page:
That's it. If you like you can configure Suhosin (see http://www.hardened-php.net/suhosin/configuration.html), although Suhosin will work out of the box with its default configuration, so be sure that you know what you're doing.