This article hasn't been updated for over 5 years. The information below may be obsolete.

Creating a simple HTTP server with python

Have you every wondered how to get a web server up and running for a simple task rather than having to configure a full blown web server like the iPlanet Web Server, Apache Web Server, or any other similar product? You haven't - Well there is a quick and dirty solution simply using python.

YES! Python has a very simple http server available.

Creating a simple python web server

  1. Create a working directory for the web server to run. For example:
    root@server:/# mkdir /test-web
  2. Copy whatever files to want to share to that working directory. For example:
    root@server:/# cp /data/users.db /test-web
    root@server:/# cp /data/users.schema /test-web
    CAUTION: Only place files into your working directory that you want to access, as any files placed in your working directory will be potentially available across your local network.

  3. Change to your working directory. For example:
    root@server:/# cd /test-web
  4. Start the web server.
    • For python2, use the SimpleHTTPServer module. For example:
      root@server:/test-web# python -m SimpleHTTPServer 8888
      Serving HTTP on 0.0.0.0 port 8888 (http://0.0.0.0:8888/) ...
      
    • For python3, use the http.server module. For example:
      root@server:/test-web# python -m http.server 8888
      Serving HTTP on 0.0.0.0 port 8888 (http://0.0.0.0:8888/) ...
      
    In both the above examples, we have started the web server using port 8888.

  5. Now, open your web browser and enter the <ip address>:<port> of the system you've started the python http server on. From there, you can select the file(s) you want to download.

NOTE: This simple web server will continue to run until you CTRL+C to terminate the session. All log information will be dumped to the terminal you run the command from.

These options work in both Solaris, and Linux envionments.


As an alternative to using a web browser to access your file(s), you could directly access the ones you want to download using commands like wget or curl.

wget <ip-address>:<port>/<filename>
curl -o <local-filename> <ip-address>:<port>/<remote-filename>

Using the files listed in step 2 and the configuration in step 4, we can perform the following:

user@client:~% wget 10.10.0.6:8888/users.db
--2016-02-16 20:19:12--  http://10.10.0.6:8888/users.db
Connecting to 10.10.0.6:8888... connected.
HTTP request sent, awaiting response... 200 OK
Length: 352176 (344K) [application/pdf]
Saving to: 'users.db'

users.db           100%[===========================================>] 343.92K  --.-KB/s    in 0.06s

2016-02-16 20:19:14 (5.53 MB/s) - 'users.db' saved [352176/352176]

user@client:~% curl -o users.schema 10.10.0.6:8888/users.schema
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  343k  100  343k    0     0  2614k      0 --:--:-- --:--:-- --:--:-- 2625k