A super-easy way to set up a local web server that even beginners can do. Requires python environment.
If it is a mac, python2.7.x is included by default.
$ python -V
python 2.7.16
You can easily start a local web server with another module even with python 2 series, but ** python 2 is no longer supported on January 1, 2020 **, so python 3 is recommended.
Execute the following command in the terminal.
$ python -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
The default port is 8000, but you can also specify the port number as follows.
python -m http.server 8080
The web server starts with the directory where this command is executed as the root.
Next, access one of the following addresses with a web browser.
#### **`http://localhost:8000`**
http://127.0.0.1:8000/

As shown above, the executed directories and files are displayed in a list.
This time, I ran a test program that displayed "Hello World!".

success!
After confirming, quit the local server with ``` Ctrl + c```.
# python 2: Use Simple HTTP Server module
The procedure is the same as python 3.
$ python -m SimpleHTTPServer Serving HTTP on 0.0.0.0 port 8000 ...
Recommended Posts