Installing Lighttpd With PHP5 And MySQL Support On Debian Etch

Version 1.0
Author: Falko Timme
Last edited 08/07/2007

Lighttpd is a secure, fast, standards-compliant web server designed for speed-critical environments. This tutorial shows how you can install Lighttpd on a Debian Etch server with PHP5 support (through FastCGI) and MySQL support.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

In this tutorial I use the hostname server1.example.com with the IP address 192.168.0.100. These settings might differ for you, so you have to replace them where appropriate.

 

2 Installing MySQL 5.0

First we install MySQL 5.0 like this:

apt-get install mysql-server mysql-client

Create a password for the MySQL user root (replace yourrootsqlpassword with the password you want to use):

mysqladmin -u root password yourrootsqlpassword

Then check with

netstat -tap | grep mysql

on which addresses MySQL is listening. If the output looks like this:

tcp        0      0 localhost.localdo:mysql *:*                     LISTEN     2713/mysqld

which means MySQL is listening on localhost.localdomain only, then you're safe with the password you set before. But if the output looks like this:

tcp        0      0 *:mysql *:*                     LISTEN     2713/mysqld

you should set a MySQL password for your hostname, too, because otherwise anybody can access your database and modify data:

mysqladmin -h server1.example.com -u root password yourrootsqlpassword

 

3 Installing Lighttpd

Lighttpd is available as a Debian package, therefore we can install it like this:

apt-get install lighttpd

Now direct your browser to http://192.168.0.100, and you should see the Lighttpd placeholder page:

Lighttpd's default document root is /var/www on Debian, and the configuration file is /etc/lighttpd/lighttpd.conf.

 

4 Installing PHP5

We can make PHP5 work in Lighttpd through FastCGI. Fortunately, Debian provides a FastCGI-enabled PHP5 package which we install like this:

apt-get install php5-cgi

 

5 Configuring Lighttpd And PHP5

To enable PHP5 in Lighttpd, we must modify two files, /etc/php5/cgi/php.ini and /etc/lighttpd/lighttpd.conf. First we open /etc/php5/cgi/php.ini and add the line cgi.fix_pathinfo = 1 right at the end of the file:

vi /etc/php5/cgi/php.ini

[...]
cgi.fix_pathinfo = 1

Then we open /etc/lighttpd/lighttpd.conf and add "mod_fastcgi", to the server.modules stanza:

vi /etc/lighttpd/lighttpd.conf

[...]
server.modules              = (
            "mod_access",
            "mod_alias",
            "mod_accesslog",
            "mod_fastcgi",
#           "mod_rewrite",
#           "mod_redirect",
#           "mod_status",
#           "mod_evhost",
#           "mod_compress",
#           "mod_usertrack",
#           "mod_rrdtool",
#           "mod_webdav",
#           "mod_expire",
#           "mod_flv_streaming",
#           "mod_evasive"
 )
[...]

and then right at the end of the file, we add the following stanza:

[...]
fastcgi.server = ( ".php" => ((
                     "bin-path" => "/usr/bin/php5-cgi",
                     "socket" => "/tmp/php.socket"
                 )))

Then we restart Lighttpd:

/etc/init.d/lighttpd restart

Share this page:

15 Comment(s)

Add comment

Comments

From: Anonymous at: 2009-02-28 02:05:57

Easy. Thanks for the info.

From: Anonymous at: 2009-10-15 18:00:34

Thank you pal! I really apreciate it, it was very helpful.

From: Anonymous at: 2009-12-13 06:14:58

Very big thanks  . gretings from Poland this tutorial is very easy and userfull

From: Jay at: 2010-03-05 00:57:12

Superb write-up! worked like a charm. Saved me time.

From: Anonymous at: 2010-08-08 03:12:38

This works awesome. Now i can finaly create a super light web server

From: Anonymous at: 2011-08-30 20:57:00

Thanks for this howto. work all well.

From: at: 2007-12-09 18:38:59

I have found this tutorial very nice and usefull. It will be interesting to see something more on lighttpd. For instance a tutorial on virtual hosting.

I have found a tutorial on virtual hosting here

From: Anonymous@estionia at: 2009-05-21 12:49:39

Thanks for help, all worked fine

From: Vanessa at: 2009-04-03 21:53:53

really nice tutorial, howtoforge is the best tutorial page where i can find much help and answers

From: Rebecca at: 2008-09-26 00:27:02

Thanks for the awesome tutorial! It was very clear and precise.

From: Spacemonkey at: 2008-09-28 14:58:23

Someone give this person a gold star for writing the one tutorial I could find that actually worked. Excellent!

From: Ferdie at: 2009-02-18 05:51:57

To All:

I was wondering if you guys can help me with this problem in the third line of the procedures: 

mysqladmin -h myserver.homenet.com -u root password 123456

This was the error:
error: 'Lost connection to MySQL server at 'reading initial communication packet', system error: 111'

I tried changing ownership of mysql /var/run/mysqld/mysqld.sock and mysqld directory itself but still can't fix this error. I had been in debian forums and followed most of their advise and end up unfixed.

Also, how do i clean up the entire mysql-server and mysql-client packages installed in debian. I made the:

apt-get remove --purge mysql-server mysql-client

and once I reinstall again,

apt-get install mysql-server mysql-client

it looks like nothing happened becuase if I do a

netstat -tap | grep mysql

no response in the console.

could you lead me on how to fix this error.

-  Ferdie.

 

 

From: Anonymous at: 2008-12-23 19:21:16

Thanks, you saved my day.

From: at: 2009-06-22 15:45:55

Great Tutorial. A quick guid to my own Webserver for my joomla page - Thank you! As a newbie I really appreciate those Step-by-Step instructions, and I like when it is explained what commands really stand for....

I exactly followed the tutorial on my vServer (Debian etch) but I got the following error after restarting Lighty

>> Starting web server: lighttpd2009-06-22 17:32:00: (mod_fastcgi.c.897) bind failed for:
>> unix:/tmp/php.socket-0 Address already in use
>> 2009-06-22 17:32:00: (mod_fastcgi.c.1330) [ERROR]: spawning fcgi failed.
>> 2009-06-22 17:32:00: (server.c.862) Configuration of plugins failed. Going down.

To solve that issue, I changed the Group of /tmp to www-data, and the permissions to 775.

bis bald,
hendrik

From: Anonymous at: 2014-01-28 21:20:12

what is the url for the phpmyadmin interface? http://192.168.2.212/phpmyadmin is not working :(