Skip to main content
blog title image

3 minute read - Tools

My search for easy to use, free, local HTTP servers

Dec 18, 2014

I have lost count of the number of times I’ve had to look for a local HTTP server.

  • Experimenting with an open source app
  • Writing some HTML, JavaScript, PHP
  • Testing some flash app for a client
  • Running some internal client code
  • etc. etc.

And since this isn’t something I do every day. I forget how to do it, each and every time I start.

I forget:

  • Which servers I already have installed
  • Where I installed them
  • Which directory I configured them to use
  • What local names did I give them to make it ’easy’ for me to work with them
  • etc. etc.

Now it might just be me that faces this problem.

If so, I expect you have already stopped reading.

So to cut to the chase, I tend to just use PHP php -S localhost:8000

Other HTTP Stacks

I have used some of the biggies:

And I probably still have them installed

And some of the tinies:

And some others that I can’t remember.

All have been useful at the time. Sometimes I tried to install one but couldn’t get it working on client machines because of permissions etc. etc.

I started looking around for alternatives that I could use during training courses, webinars etc.

Some I have not used

Prior to writing this post I was aware that Python had the capability to start up a small http server from the command line, but I hadn’t used it. After publication, Brian Goad tweeted his usage of Python to do this.

@eviltester also useful for non-Python scripters. I have an alias setup alias simple-server='cd ~/server/; python -m SimpleHTTPServer'
— Brian D. Goad (@bbbco) December 18, 2014

Brian continued:

could be easily used as a function that takes the dir as argument:

simple-server(){ cd $1; python -m SimpleHTTPServer; }

just go to localhost:8000 and you’re set!

After Brian’s reminder I had a quick look to see what other languages can do this:

Virtual Machine Stacks

One thing I started using were virtual machines that have software installed already and don’t require a web server e.g.

These are great for getting started quickly, but require a little download overhead - which can be painful over conference internet connections.

Sometimes I set up machines in the cloud, preinstalled:

As an additional backup, I like to have a local version that I can share.


A simple one liner for Ruby users:

ruby -run -e httpd . -p 5000 (or whatever port you prefer)

Just navigate to the directory you want to serve in your command line and then run this, assuming you have Ruby on your system. But you can’t go wrong with Python, either.

If you are on a *nix platform and want to capture the stdout/stderr streams to a file for reference later, simply add “2>&1 | tee outfile” to the end so it looks like this:

ruby -run -e httpd . -p 5000 2>&1 | tee outfile

In a nutshell, you are telling your Ruby install to:

  1. run the httpd server, serving your current directory (".") on port 5000
  2. and capturing the stdout && stderr, piping it to the “tee” program, which dumps it into the plain text file “outfile”