Monday, 29 April 2013

PHP: built-in web server

This is a real quick one as I have only 20min before I'm due to start work. And I need to go to the supermarket yet to get my breakfast.

So far I'm messed around with running PHP on Apache and IIS, and I think I lamented that PHP didn't seem to have a built-in web server option (although whether this made it into an article I'm not sure: I can't find it). Well whilst reading some docs during my KL to London flight last week, I saw mention of a built-in web server, so I decided I'd better look into this at some stage.

I'm at work as I said, and I am not an administrator on my work PC, but I do most of my blog-writing at my desk before office hours or at lunchtime. And to write about PHP stuff, I kinda need to have PHP running.

Running PHP is easy enough as a non-admin as to install it is just to unzip it, so that's easy. But I cannot mess with IIS and I cannot install Apache. Time to check this built-in web server.

Google to the rescue. I googled "php built-in web server", and the first link goes to the instructions.

It could not be easier. Basically open a command line, browse to my PHP dir, and type this:

php -S localhost:8000 -t D:\websites\php.local

And there I was, up and running. So from start to finish, the steps to get PHP running locally is this:
  1. Googled the PHP download site;
  2. download it;
  3. unzip it;
  4. copy the [php]\php.ini-development file to php.ini;
  5. stick my doc_root value in;
  6. open a command line in the PHP dir;
  7. run that command line as per above.
That all takes about 5min, max. I reckon I could get it down to about 1min, with practise.

I haven't found a way to switch directory browsing on with this web server yet, but I'll look into this some more (or if you know, pls do tell!).

Fastest blog entry ever: 9min start to finish.