Put Your PHP on Port 3000 With Lighttpd
While most of my work these days is in a Ruby and Rails environment, I still get my hands dirty with PHP every now and again.
When working with web projects I practically require the ability to use absolute links for static content. Because of this, I usually have to host a PHP project under Apache and create a virtual name, oh and make a fake host entry in my hosts file. Blegh.
This usually sucks even more when I throw in the fact that my project is under some kind of source control (which is usually always the case). So what is a frustrated developer to do?
Well, the only reason this is annoying is because I don’t have to deal with it in my
script/server world of Rails development. So I solved my litle PHP problem by borrowing from what I learned with Rails.
Instead of developing PHP apps under Apache, I installed Lighttpd and fire off an instance whenever I need to do work on the app. Very simply I added a lighty config file under
APP_ROOT_/config and when I want to work on my PHP app, I just start lighty. Booom. Now I have my app running at localhost:3000. Just like my Rails apps, so my fancy bookmark in my bookmark bar works for both my PHP and Rails projects. Now that DRY!
So, how do you get it going like this? First off, all of these instructions were done in OS X 10.5 Leopard, so be warned.
Roll Your PHP
You need to roll your own PHP in order to get support for php-cgi. Do this:Pretty basic. Download, configure, make, and install PHP. Next, rename the php binary, use tab complete I think the XXX part is different per install(?)
Ok, I’m not a big fan of MacPorts, but I was having so much trouble getting Lighttpd installed on Leopard, that I had macports do it for me. So, go install macports first and:
Set Up Your App
Ok, you’re all set up. Now you just need to add a lighttpd config file to your app. Create APP_ROOT/config/lighty.conf with this:
Now you’re deving with port 3000. Plus, your app isn’t constantly available and just sitting there. When you need to work on it, fire it up, work, and shut’r down.