Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

Install PHP 5.3.0/Lighttpd On Debian (Lenny) With Imap, MySQL, Sqlite3 And ImageMagick Support

This tutorial covers the setup of PHP 5.3.0/Lighttpd on Debian (lenny) with imap, mysql, mysqli, sqlite3, ImageMagick and mycrypt support.

For this tutorial I will assume you are logged in as root this is not advised.

First we need to install the webserver:

aptitude install lighttpd

Now we install the packages needed for mysql and mysqli support. You will be promoted to enter a mysql root password – please use a strong password.

aptitude install mysql-server mysql-client libmysqlclient15-dev

Next install some packages php needs to compile.

aptitude install libtidy-dev curl libcurl4-openssl-dev libcurl3 libcurl3-gnutls zlib1g zlib1g-dev libxslt1-dev libzip-dev libzip1 libxml2 libsnmp-base libsnmp15 libxml2-dev libsnmp-dev libjpeg62 libjpeg62-dev libpng12-0 libpng12-dev zlib1g zlib1g-dev libfreetype6 libfreetype6-dev libbz2-dev libxpm-dev libmcrypt-dev libmcrypt4 sqlite3 bzip2 build-essential libreadline5-dev libedit-dev

Install packages required for imap support. You will be promoted to enter a domain for Kerberos – normal practice is to set this as the domain name of your server in uppercase. eg MYSERVER.COM:

aptitude install libc-client2007b libc-client-dev krb5-kdc openssl

Install the packages required for ImageMagick support:

aptitude install libmagick++9-dev imagemagick libmagick10 autoconf

We can now download the php source files. First make sure you are in your home directory.

cd ~

Download the php-5.3.0 source code form the php website:


Once the file is done downloading extract the file into your home directory:

tar -xvf php-5.3.0.tar.gz

We are going to add support for ImageMagick. To do this we add the pecl package into the source code so it can be included on compile. Please note ImageMagick can be added after compile and loaded dynamically via the php.ini file. For more information on this method see

Change directory to the etc directory in your php source directory. This is where php looks for pecl packages:

cd ~/php-5.3.0/ext/

Download, extract and rename the ImageMagick package:

tar -xvf imagick-2.2.2.tgz
mv imagick-2.2.2 imagick

Change back to the root of the source directory:

cd ~/php-5.3.0/

We now need to generate a new config file that takes into account the addition of ImageMagick. First remove the old config file:

rm configure

Next run the buildconf tool to generate a new config file. You will see some warnings – they can be safely ignored:

./buildconf –force

We can now run the configure command:

./configure -with-mysql=/usr -with-mysqli=/usr/bin/mysql_config -with-tidy=/usr -with-curl=/usr/bin -with-curlwrappers -with-openssl-dir=/usr -with-zlib-dir=/usr -enable-mbstring -with-xpm-dir=/usr -with-pdo-mysql=/usr -with-xsl=/usr -with-ldap -with-xmlrpc -with-iconv-dir=/usr -with-snmp=/usr -enable-exif -enable-calendar -with-bz2=/usr -with-mcrypt=/usr -with-gd -with-jpeg-dir=/usr -with-png-dir=/usr -with-zlib-dir=/usr -with-freetype-dir=/usr -enable-mbstring -enable-zip -with-pear -prefix=/usr/php -with-imap -with-kerberos -with-imap-ssl -with-imagick -with-readline -with-libedit

Assuming there were no errors we can now compile and install php:

make install

We now need to enable fastcgi in lighttpd and tell it to use our newly compiled php binary.

First edit the lighttpd fastcgi config file:

nano /etc/lighttpd/conf-available/10-fastcgi.conf

Edit the config file so it reads:

## FastCGI programs have the same functionality as CGI programs,
## but are considerably faster through lower interpreter startup
## time and socketed communication
## Documentation: /usr/share/doc/lighttpd-doc/fastcgi.txt.gz
server.modules += ( “mod_fastcgi” )
## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server = ( “.php” =>
“bin-path” => “/usr/php/bin/php-cgi”,
“socket” => “/tmp/php.socket”,
“max-procs” => 2,
“idle-timeout” => 20,
“bin-environment” => (
“bin-copy-environment” => (
“broken-scriptfilename” => “enable”

Now enable mod fastcgi and restart lighttpd:

lighttpd-enable-mod fastcgi
/etc/init.d/lighttpd force-reload

To test your php install create the file info.php in the /var/www/ directory:

nano /var/www/info.php

Edit the file so it reads:


Finally test your install by going to http://myserver/info.php.

It is also a good idea to create a php.ini file; for more info on this see