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/
![スクリーンショット 2020-06-26 7.11.29.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/660621/db1c1f7e-8302-484b-25fe-d544d253be1c.png)
As shown above, the executed directories and files are displayed in a list.
This time, I ran a test program that displayed "Hello World!".
![スクリーンショット 2020-06-26 7.17.06.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/660621/696c9855-a73d-3f3b-aa1a-990b2eb4d677.png)
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