Last Updated: September 09, 2019
·
5.789K
· jelle

Easiest way to start a basic local webserver.

Want to serve some static files through a webserver? To test for instance ajax requests? To display to the outside world? Or to test fancy url's? Start up a web server in your current dir in a second by launching this command in your terminal:

python -m SimpleHTTPServer

This works out of the box with python, which is installed by default on nearly any unix platform (os x, ubuntu, etc.).

8 Responses
Add your response

I actually have this setup in my .bashrc like:

# serve dir as static site
alias serve="python -m SimpleHTTPServer"
over 1 year ago ·

If you want to give access to served folder to anyone you can use localtunnel Ruby gem:

python -m SimpleHTTPServer 8000
localtunnel 8000
over 1 year ago ·

And if you want more flexibility, mongoose is a good tiny HTTP server.

over 1 year ago ·

http://nginx.org/en/download.html Nginx is my choice for quick tests under Windows [and it has replaced Apache on my internal Linux server].

over 1 year ago ·

I knew that newLISP has its own http deamon, but I never knew that python had the same. Cool!

over 1 year ago ·

Is there a way I can make the python module find an available port to serve so I can start multiple servers by running the same command in different directories?

over 1 year ago ·

Here's a tribute to your tip :)
Simple HTTP server from Nautilus context menu

over 1 year ago ·

if you often work on multiple services at once, and don't mind using npm packages, http-server is great: it automatically finds an available port if you don't specify one:

> npm install -g http-server
> http-server
Starting up http-server, serving ./ on port: 8080
Hit CTRL-C to stop the server
...
> http-server&
Starting up http-server, serving ./ on port: 8081
> http-server&
Starting up http-server, serving ./ on port: 8082
over 1 year ago ·