mp4tva
Last Updated: October 09, 2017
·
4.851K
· 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

1976

I actually have this setup in my .bashrc like:

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

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 ·
2051

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

over 1 year ago ·
2139

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 ·
2179

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

over 1 year ago ·
3419

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 ·
3420

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

over 1 year ago ·
3807

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 ·