Thursday, 18 December 2014

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


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, my current favourites are Mongoose (Windows, Mac, Linux) and VirtualHostX (Mac)


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.

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:

If you know of any more languages that have this as part of their default then leave a comment and I'll add them here.

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.

VirtualHostX for the Mac

Since I mainly travel with a Mac Laptop I started using VirtualHostX for that.

VirtualHostX is basically a GUI that helps me work with the existing Mac installed LAMP stack.

I can avoid the Mac and command line config. I can avoid installing everything else, and just use VirtualHostX to configure and start/stop everything.

This saved a massive amount of time for me and I do recommend it. But it is Mac only.

Mongoose for Mac, Windows and Linux

I recently encountered Mongoose. It works on Mac, Windows and Linux. 

I used the free version to quickly experiment with some downloaded open source libraries. 

All you do is download the small executable into the directory, run it, and you get the traditional XAMPP style taskbar tooltip icon and easy to use config. 

You can run multiple versions by having them listen on different ports.

I paid $8 for the Windows dev version which allows me to view the HTTP traffic easily as well. This $8 also gives me access to the Linux Pro version. For an extra $5 I could get access to the MacOS pro version.

Summary

I suspect that 'proper' web developers will always prefer an XAMPP installation. But they will also use it more and be completely familiar with it.

For someone like me, who jumps between apps, configs, machines, sites, etc. 

I suspect that at some point I'll probably jump back to  XAMPP due to some future client needs. But for my own work. VirtualHostX and Mongoose are my current easy to use solutions.

What do you use?

4 comments:

  1. It's rare that my use case extends beyond Python's SimpleHTTPServer. It's especially handy for sharing an arbitrary directory of files to Windows users from Linux.

    ReplyDelete
  2. Thanks Dan. I saw mention of that in a few places during my hunt. For anyone interested here are some links

    * http://www.linuxjournal.com/content/tech-tip-really-simple-http-server-python

    * http://www.pythonforbeginners.com/modules-in-python/how-to-use-simplehttpserver/

    ReplyDelete
  3. Seems like php also has a similar web server built in

    * http://serverfault.com/questions/338394/how-to-run-php-with-simplehttpserver

    ReplyDelete
  4. 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"

    HTH

    ReplyDelete