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.).
Written by Jelle
Related protips
8 Responses
I actually have this setup in my .bashrc
like:
# serve dir as static site
alias serve="python -m SimpleHTTPServer"
If you want to give access to served folder to anyone you can use localtunnel
Ruby gem:
python -m SimpleHTTPServer 8000
localtunnel 8000
And if you want more flexibility, mongoose is a good tiny HTTP server.
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].
I knew that newLISP has its own http deamon, but I never knew that python had the same. Cool!
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?
Here's a tribute to your tip :)
Simple HTTP server from Nautilus context menu
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