To set up a basic HTTP server using Python, you can use the http.server module. Here’s how to do it:
Using Python 3
-
Open your terminal or command prompt.
-
Navigate to the directory where you want to serve files. For example:
cd /path/to/your/directory -
Run the following command to start the server:
python3 -m http.server 8000This command starts a simple HTTP server on port 8000. You can change
8000to any other port number if needed. -
Access the server by opening a web browser and navigating to:
http://localhost:8000
Using Python 2 (if needed)
If you're using Python 2, the command is slightly different:
python -m SimpleHTTPServer 8000
Stopping the Server
To stop the server, go back to your terminal and press Ctrl + C.
This setup allows you to serve files from the specified directory and is useful for testing and development. If you have any further questions or need additional help, feel free to ask!
