Sometimes you need to quickly run a simple HTTP server on your localhost to test or try something.

If you already have Python installed, then you don’t need to go through installing a separate web service like Apache HTTPD or NGINX.

Instead, cd to the directory where your .html files are located, then run the following command:

$ python -m SimpleHTTPServer 80
Serving HTTP on 0.0.0.0 port 80 ...
127.0.0.1 - - [25/Mar/2020 15:03:44] "GET / HTTP/1.1" 200 -

Note that Python 3 syntax is slightly different:

$ python3 -m http.server 80
Serving HTTP on :: port 80 (http://[::]:80/) ...
::1 - - [25/Mar/2020 15:03:44] "GET / HTTP/1.1" 200 -

If you had the following file index.html:

<html>
  <head>
    <title>Test Page</title>
  </head>
  <body>
    <div>My test page</div>
  </body>
</html>

It would look like this:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.