A Path Less Taken

Breaking with convention in a very conventional fashion. Powered by WordPress

"What would you attempt to do if you knew you could not fail?"
Dr. Robert Schuller

Wednesday, February 11, 2009

Category: Web Development Author: JJ 2 Comments

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.

  1. 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.
  2. 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.
  3. 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.

  4. 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
  5. The LightTPD.exe showed up in the Process List in the Windows Task Manager.
  6. 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.
  7. 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.
  8. 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.
  9. 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.

  10. 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.
  11. 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

2 Comments to “Installing Lighttpd and PHP on a USB Drive”

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">