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

Want to support HowtoForge? Become a subscriber!
 
Submitted by zabouth (Contact Author) (Forums) on Wed, 2009-07-22 18:26. :: Debian | Lighttpd | PHP

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:

wget http://us3.php.net/get/php-5.3.0.tar.gz/from/this/mirror

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 http://uk.php.net/manual/en/install.pecl.pear.php.

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:

wget http://pecl.php.net/get/imagick-2.2.2.tgz
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
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
##                http://www.lighttpd.net/documentation/fastcgi.html
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" => (
                        "PHP_FCGI_CHILDREN" => "4",
                        "PHP_FCGI_MAX_REQUESTS" => "10000"
                ),
                "bin-copy-environment" => (
                        "PATH", "SHELL", "USER"
                ),
                "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:

<?php
phpinfo();
?>

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 http://us2.php.net/manual/en/ini.php.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Shamli (not registered) on Sun, 2011-08-21 11:22.

After installing following the setup above..by replacing the php version and imagick as below:

http://pecl.php.net/get/imagick-3.0.1.tgz

http://www.php.net/get/php-5.3.7.tar.gz/from/this/mirror

the php-cgi was installed in different directory....whereby you have to change as below:

## 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
##                http://www.lighttpd.net/documentation/fastcgi.html
server.modules   += ( "mod_fastcgi" )
## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server    = ( ".php" =>
    ((
##        "bin-path" => "/usr/bin/php-cgi",
        "bin-path" => "/usr/php/bin/php-cgi",
        "socket" => "/tmp/php.socket",
        "max-procs" => 2,
        "idle-timeout" => 20,
        "bin-environment" => (
            "PHP_FCGI_CHILDREN" => "4",
            "PHP_FCGI_MAX_REQUESTS" => "10000"
        ),
        "bin-copy-environment" => (
            "PATH", "SHELL", "USER"
        ),
        "broken-scriptfilename" => "enable"
    ))
)
Submitted by Anonymous (not registered) on Fri, 2010-12-10 23:01.

Hi,

thanks for your great 'tutorial'.
I'm new to linux.

I've followed your steps (./configure ..... , make , make install )
everything worked ok.
But when I call a phpinfo() it still shows my old version (5.2.x) :(
Even if I restart apache.

Submitted by psykosen (not registered) on Mon, 2010-09-27 05:07.

Tak you for the this nice howto.!
install php5.3.3
just changed
wget http://us3.php.net/get/php-5.3.0.tar.gz/from/this/mirror
to
wget http://us3.php.net/get/php-5.3.3.tar.gz/from/this/mirror

no problems there  using the MySQL Vhost
http://www.howtoforge.com/creating-simple-vhosts-with-mod_mysql_vhost-on-lighttpd-debian-etch
with this one NO PROB what so ever Debian 5.0.6 (Lenny)

AND many tanks for the site.! using it allot.!
Regards

Submitted by dpkg-deb (not registered) on Wed, 2010-08-11 11:54.

Not meaning to come across as nasty here, but this guide is not correct - it's not the correct Debian way to simply grab some build dependencies and then ./confgure make make install away.  You should be building a Debian package from your source and using that to install and maintain your binaries.  Doing it the simple way above will just throw binaries all over the place and pollute your system if you need to upgrade it or change your version.

Look for a guide on building Debian packages - you can apt-get source php5 from within Debian and see how they have Debianized the PHP as a package, properly.

M

Submitted by Richard (not registered) on Wed, 2009-12-16 13:43.

Thank you very much, it is really usefull

Submitted by Martin Petrov (not registered) on Wed, 2009-10-21 16:32.
Again if you bulgarian here you find howto compile and install php 5.3 on Debian Lenny- http://mpetrov.net/kompilirane-i-instalirane-na-php-53-na-debian-lenny
Submitted by Merlin (not registered) on Sat, 2009-09-19 21:01.

Hi,

I have written a PHP script to find alexa rank. But its not working on Debian kernel. I have tried it on Redhat Kernel and windows , it works fine.

 Please let me know...

 Here is the Original Page: http://www.techunits.com/content/2397/how_to_find_alexa_pagerank_with_php