Last Updated: September 09, 2019
·
3.14K
· groodt

One line web server

It is often very useful to be able to serve a local directory through a web server when debugging a static website, sharing files on a network etc.

With Python 2.4+, it is a simple one liner:

python -m SimpleHTTPServer

In Python 3, it becomes even shorter:

python3 -m http.server

This will setup a simple web server rooted at your current directory listening on port 8000. On OSX and Linux you almost certainly have Python installed, so there are no dependencies.

I've got this saved as a script called 'serve-here' on my path so I don't need to remember it:

#!/bin/sh
python -m SimpleHTTPServer

It is only a very simple single-threaded web server, not at all suitable for many users or large files, but more than capable for local testing and simple file sharing.