Create a HTTP server with one command thanks to Python

Not a new trick by any means, but if you need a simple HTTP Server to serve files from directory, Python makes this easy.

Note: If you don?t have Python installed (most likely you?re on Windows), get an installer from http://python.org/

To run the server:

  • Open a terminal window.
  • Navigate to the directory you want to have the root directory.
  • Execute the command to start the server.
  • Python 2 ? python -m SimpleHTTPServer 8000
  • Python 3 ? python -m http.server 8000

Then open a web browser at http://localhost:8000/.

This command will start a single threaded HTTP server bound to 0.0.0.0, the (simple) implications of which are that it is able to respond to internal and external requests.

I used port 8000 above but you can chose any port you want, although any port number below 1024 may give you permission denied errors if not executing as root.

More info about the SimpleHTTPServer available at http://docs.python.org/library/simplehttpserver.html

12

No Responses

Write a response