How to Setup a Server With Python in 10 minutes

Install Python

Ensure Python is installed on your system. Verify it by running python --version or python3 --version in your terminal.

Navigate to Your Directory

Open your terminal, navigate to the folder where you want to set up the server, and make it your working directory.

Start an HTTP Server

Run python -m http.server for Python 3 or python -m SimpleHTTPServer for Python 2 to initiate a basic HTTP server.

Specify a Port (Optional)

Add a port number to the command (e.g., python -m http.server 8000) to run the server on a specific port instead of the default (port 8000).

Access the Server

Open a browser and type http://localhost:8000 (or the specified port) to view the server’s content in your browser.

Stop the Server

To stop the server, press Ctrl+C in the terminal. This will terminate the running process.