Set up a local web server in 30 seconds using python 3's http.server

A super-easy way to set up a local web server that even beginners can do. Requires python environment.

Checking the 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.

python 3 series: use http.server module

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

Set up a local web server in 30 seconds using python 3's http.server
Set up a simple HTTPS server in Python 3
Set up a test SMTP server in Python.
Set up a simple SMTP server in Python
I want to set up a mock server for python-flask in seconds using swagger-codegen.
Set up a mail server using Twisted
Set up a local server with Go-File upload-
Set up a UDP server in C language
Set up a local server with Go-File download-
How to set up a local development server
How to set up a Python environment using pyenv
Set up a file server on Ubuntu 20.04 using Samba
Set up a free server on AWS in 30 minutes
[Python] I tried running a local server using flask
[Vagrant] Set up a simple API server with python
How to host web app backend processing in Python using a rental server subdomain
How to set up a simple SMTP server that can be tested locally in Python
Turn your Android Smart Phone into a Web Server using python.
I get a can't set attribute when using @property in python
Run the output code on the local web server as "A, pretending to be B" in python
Set up a Samba server with Docker
Scraping a website using JavaScript in Python
Draw a tree in Python 3 using graphviz
Send mail with mailx to a dummy SMTP server set up with python.
Set up a dummy SMTP server in Python and check the operation of sending from Action Mailer
Introduction and usage of Python bottle ・ Try to set up a simple web server with login function
Put Docker in Windows Home and run a simple web server with Python
Set up a simple HTTPS server with asyncio
Create a GIF file using Pillow in Python
Creating numbering process using python in DynamoDB Local Numbering process
Create a web map using Python and GDAL
Steps to develop a web application in Python
View drug reviews using a list in Python
Launch a web server with Python and Flask
Set up a Python development environment on Marvericks
Create a MIDI file in Python using pretty_midi
Create a web server in Go language (net/http) (2)
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer
Set up a file server using samba on ZeroPi of Friendly Arm [OS installation]
Hello World is a simple web server that follows WSGI (Web Server Gateway Interface) in Python.
Set up an FTP server that can be created and destroyed immediately (in Python)
Set up a file server using samba on ZeroPi of Friendly Arm [Purchased Items]
Set up a file server using samba on ZeroPi of Friendly Arm [Personal import]
(Python) Try to develop a web application using Django
[Part 1] Let's set up a Minecraft server on Linux
Learning neural networks using Chainer-Creating a Web API server
Create a web server in Go language (net / http) (1)
Set up a Minecraft resource (Spigot) server via docker
How to execute a command using subprocess in Python
Create a fake Minecraft server in Python with Quarry
Setting up Jupyter Lab in a Python 3.9 venv environment
Set up a Python development environment with Sublime Text 2
HTTP server and HTTP client using Socket (+ web browser) --Python3
Set a proxy for Python pip (described in pip.ini)
DNS server in Python ....
Local server with python
Script to count and stop up to 5 seconds in Python in Blender
Test.py is not reflected on the web server in Python3.
Set up a Python development environment with Visual Studio Code
Create a local scope in Python without polluting the namespace
[Django3] Display a web page in Django3 + WSL + Python virtual environment