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)
- Free VirtualHostX has a free trial. Mongoose is free for personal use.
- Cheap For commercial use, both are cheap VirtualHostX ($49), Mongoose ($5-$8)
Other HTTP Stacks
I have used some of the biggies:
- WAMP
- MAMP
- XAMPP
- Easy PHP DevServer (which was fairly easy)
- Portable versions
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:
PHP has a built in webserver
Python (as mentioned above)
- Official docs
- Example from linuxjournal
- Example from PythonForBeginners
_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:
- On Amazon VMs either using bitnami or the marketplace
- Azure seems to have a similar marketplace
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?
- Zeff Morgan provided the following information
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:
- run the httpd server, serving your current directory (“.”) on port 5000
- and capturing the stdout && stderr, piping it to the “tee” program, which dumps it into the plain text file “outfile”
HTH
You will need a Github account to comment. Or you can contact me with your comment.
I reserve the right to delete spam comments e.g. if your comment adds no value and its purpose is simply to create a backlink to another site offering training, or courses, or etc.