This quick tip shows how to easily create a basic HTTP download server in Linux both Desktop and Server with Python.
Python is a popular programming language pre-installed in most Linux systems. It comes with a module for implementing HTTP web servers.
Check Python version.
Python 2.x and 3.x have the HTTP module with different names. While most Linux in 2020 have Python 3.x, some old systems may still ship with Python 2.
python --version
python3 --version
Single command to setup basic HTTP server:
Warning: This is not recommended for production use.
For Python2, use python -m SimpleHTTPServer
instead in following commands.
Open terminal or connect to your Linux server, then run command:
- Create HTTP server with default port 8000, serve files in the current working directory:
python3 -m http.server
- If port 8000 is already in use, run command below instead to specify another port (8800 in the case):
python3 -m http.server 8800
- Instead of current directory, you can also specify a folder to serve:
python3 -m http.server 8899 --directory /usr/share/backgrounds/
In the case, it serves files in
/usr/share/backgrounds
with port 8899. And adding & in the end of command will make it run silently in the background.
How to Access the HTTP File Server you created:
In any device, desktop PC, notebook, mobile phone, with a web browser, go to URL: “IP_ADDRESS:port_number”
If the Linux machine has public IP, you’ll be able to access the HTTP server anywhere with internet connection.
If the Linux is behind a home network router and you want to access outside your network, edit your router’s configuration to forward port 8000 (or other port you specified) to the computer on which you ran the Python command.
Recent Comments