Ubuntu 18 Start simple web host with python on localhost

Python is part of Ubuntu so you can use python to start: SimpleHTTPServer(Since Ubuntu 16.04 Python 3 is included by default). This is really quick and out of box solution to run web server on your Ubuntu 18 machine.

How to use it

You can start it simply by command: python -m SimpleHTTPServer (starting at port 8000) or by providing a port. You have to in the folder that you want to be served. So open your terminal by CTRL+ALT+T:

cd \home\folder\site
python -m http.server 8080

or : python3 -m http.server 8080 - depending on your python settings

If you have python 2 than you can run:

cd \home\folder\site
python -m SimpleHTTPServer 8080

result:

python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8080 ...

Once started you can access all the files that you serve to address:

http://localhost:8080/

Run the server after close of terminal

If you stop your session in terminal the server will stop too. In order to run it even when terminal is closed use nohup - no hung up command:

nohup python -m http.server 8080 &

Check Python version

In order to check your python version use:

python --version
python -V

result:

python --version
Python 2.7.6

More information:

Simple HTTP request handler

Related Article