After a bit of head scratching (and manual reading, who knew) I finally got PHP working as a CGI on lighttpd (Lighty). I decided to share my approach here in case you wanted to give it a shot yourself. I tested this briefly on Windows XP Professional and Windows Vista Ultimate and it worked on both.
- I downloaded the binaries for lighttpd and PHP. As stated in a previous post I obtained the lighttpd binaries from here. They were produced by the WLMP Project. I chose the .ZIP package without the setup since I wanted to do the installation manually on a USB Drive. I obtained the PHP binaries from here. Again I chose the first .ZIP package without the installer.
- Extract the LightTPD directory with all of it’s contents from the .ZIP file and copy it to your USB Flash Drive. I put mine in the root folder of my drive.
- Because I was going to use the USB Flash Drive on a computer that already had Apache installed and running on Port 80, I went into the conf folder and edited the lighttpd-inc.conf file. I changed the server.port variable to equal 81 which in my case was just removing the # comment tag from the front of it. In the server.modules section I made sure that the following modules were the only ones uncommented:
- mod_access
- mod_accesslog
- mod_alias
- mod_cgi
- mod_fastcgi
- mod_status
I made sure cgi.assign was uncommented for the .php option and I set it equal to the literal path of php-cgi.exe file on the Flash Drive. This can probably be handled with a variable if you choose to take that approach. That would avoid drive letter issues on different computers. Then I saved and closed the file.
- Since I was using Windows Vista (think User Access Control or UAC) I opened a command prompt using the “Run as administrator” right click option. In the command window I navigated to in my case the E:\LightTPD directory and ran the following command.
lighttpd -f conf/lighttpd-srv.conf -m lib -D
- The LightTPD.exe showed up in the Process List in the Windows Task Manager.
- I opened up my favorite web browser (Google Chrome in my case) and navigated to http://localhost:81/ and the LightTPD test page was displayed.
- If you encounter a problem with this you may need to add LightTPD.exe to your Windows Fire Wall list of accepted applications in order to make this work correctly.
- Next I shut down the server (Ctrl+C) and created a php folder at the root of the Flash Drive. I copied the contents of the .ZIP into this folder.
- In the php folder I changed the php.ini-recommended file name to php.ini and edited the file. I changed the doc_root property to the root document folder of the lighttpd web server (in my case “e:\lighttpd\htdocs”). I also made sure that the following extensions were not commented out:
- php_mbstring (for Unicode strings)
- php_mcrypt (for encrypting cooking contents)
- php_sqlite (as the db engine I planned to use on my portable development drive)
Each of the above were things I wanted on my development environment and are not required for this to work. Then I saved and closed the file.
- This next part had me stumped for a while. In the PHP Installation guide it said that one of the options for making sure php.ini can be seen by the web server and allow PHP to work as a CGI was to copy the php.ini file into the folder with your web server. I copied the php.ini file to in my case e:\lighttpd.
- I created test.php with the phpinfo function and requested the file URL in my browser. I was rewarded with the PHP Info page.
That was all it took to get lighttpd and PHP up and running on my USB Drive. I will update this post if there is any additional configuration changes needed to access SQLite on the USB Drive
Peace


Awesome!
So can you use that USP drive web server by plugging into any PC?
@Amitabh Yes. You just run the command from step 4 above from a DOS prompt that has admin permissions. You might want to check out this other post to see how I fixed a performance problem on both Windows XP and Windows Vista.
http://www.legendrefamily.org/blog/2009/02/installing-lighttpd-php-and-sqlite-on-a-usb-drive/