Firas Chaaben's Blog

Simple http server python

Published 20/11/20225 min read
image

SimpleHTTPServer is a python module which allows you to instantly create a web server or serve your files in a snap. Main advantage of python’s SimpleHTTPServer is you don’t need to install anything since you have python interpreter installed. You don’t have to worry about python interpreter because almost all Linux distributions, python interpreter come handy by default..

Code Block

Sometimes as admins, we need to share files across systems quickly. For whatever reason, we need to get a single tar or conf file from one system to another, or maybe copy a group of files between systems. We find that we need to install a package or utility to share the files, or we may need to enable a feature to share the content. Regardless of the situation, we can use Python's SimpleHTTPServer module as a quick web server. .

					    
# If Python version returned above is 3.X
# On Windows, try "python -m http.server" or "py -3 -m http.server"
python3 -m http.server
# If Python version returned above is 2.X
python -m SimpleHTTPServer
					    
				    

Thats just it, fire up your browser and the present directory files can be seen on http://localhost:8000. If the directory has a files name such as index.html, then that file will served as the initial file. Otherwise all the files present in the directory will be listed. If port 8000 is already being by any other server, the above mentioned command accepts an optional port number as well. .

					    
python -m SimpleHTTPServer 
	
python3 -m http.server