Simple way to serve static folders locally

As a developer I run into a lot of situations where I need to fire up a quick web server to perform some task. Python ships with osx and makes this task quite simple.

In terminal enter:

cd path/to/my/dir
python -m SimpleHTTPServer 8080

If you have Python installed and all went well the terminal will output this:

Serving HTTP on port 8080 ...

Now you can access the directory in your browser http://localhost:8080. If you are loading a static website the root url should load the index.html, otherwise it’ll be a directory listing of the files in that folder.

Depending on the network, the web server should be viewable on other devices on the same network. To reach the server you will need to find the IP address of the host machine along with the port number we started the server on. Enter this into a browser on the target device. ie. and browse away.

If we need to run multiple web servers or switch the port, just change the port param in the command 8080 to the desired port 3333.

python -m SimpleHTTPServer 3333

Read more: 20.19. SimpleHTTPServer — Simple HTTP request handler — Python 2.7.11 documentation