Howto: Lighttpd, PHP and MySQL on Windows

Posted by Luca on May 16th

What? No posts for two and a half weeks, what is going on? Well unfortunately James and I have both had quite a bit of uni work to do. James has got his exams in a couple of weeks and then finishes at the beginning of June. I have had a couple of group projects, but I haven’t got my exams for four weeks so I should be able to get a bit more work done over that time.

Unfortunately I am going to have to send my MacBook back as I am having a few problems with it, this means I am going to be stuck on Windows until the repair has finished so I was wondering what to do for development. On my Mac I have Apache, PHP and MySQL. There are plenty of tutorials, and even packages that do this for you for Windows but I wanted something a tad different so in this howto I am going to explain how to install Lighttpd, PHP and MySQL on Windows.

What you will need
Lighttpd Windows binaries (1.4.15)
PHP (5.2.2)
MySQL (4.1.22)

It is probably a good idea to use whatever version of PHP you are using on your production server, most hosting companies will be using 5.1 rather than 5.2 as linked to above.

Installation
This is nice and easy, just run the installers. The order shouldn’t make any difference but I did it this way: Lighttpd, PHP, MySQL. When installing Lighttpd your virus checker will probably say there is a virus in process.exe, if you have problems it is probably best to close your virus scanner while installing. Information on process.exe can be found here. When installing MySQL it will ask you to create an account, you shouldn’t need it so just click Skip Sign-Up. When configuring you will want to set the type as Multifunctional or Transactional. During the PHP configuration it will ask you for a server type, select Other CGI and from the list of extensions select MySQL.

Configuration
First you need to get lighttpd working, after the installation it wouldn’t work for me without a little change. Go to C:\lighttpd\etc\ and make a copy of the file lighttpd.conf.orig called lighttpd.conf. After this you should be able to run the start script, and if you navigate to http://127.0.0.1/ you should be greated with the startup page!

Next you need to configure PHP to work. This is again nice and easy. You need to edit C:\lighttpd\etc\lighttpd.conf. First find the line with “mod_cgi” on it and uncomment it by removing the #. The add the following to the bottom of the file:

cgi.assign = ("php" => "C:\\Program Files\\PHP\\php-cgi.exe" )

You may need to change it if you installed PHP to a different location, but make sure you point it to php-cgi.exe not php.exe!

Testing

We can kill two birds with one stone by getting a list of MySQL databases from a PHP script! To do so put the following in C:\lighttpd\htdocs\test.php:

< ?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$db_list = mysql_list_dbs($link);

while ($row = mysql_fetch_object($db_list))
{
     echo $row->Database . "\n";
}
?>

(Argg WP sucks for code… “n” should have a backslash before it)

And then go to http://127.0.0.1/test.php, and if you have got it all working you should get a list of the databases!

2 Comments »

  1. Nice job guys, great tutorial you have here. I think you may have a slight mistake in your test script though–the line in the while loop should have “\n” rather than just “n” if your trying for a newline. Cheers.

    Comment by Matt — 24th of May, 2007 @ 3:29 am

  2. Thanks Matt!

    You are right, there should be a backslash there, but for some reason Word Press gets rid of it….

    Comment by Luca — 24th of May, 2007 @ 4:24 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment