Create a HTTP server with one command thanks to Python (2024)

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

Check out https://ryanblunden.tech for more developer content.

Create a HTTP server with one command thanks to Python (2024)
Top Articles
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 5808

Rating: 5 / 5 (80 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.