How to Use Python ‘SimpleHTTPServer’ to Create Webserver or Serve Files Instantly

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.

You also can use SimpleHTTPServer as a file sharing method. You just have to enable the module within the location of your shareable files are located. I will show you several demonstrations in this article by using various options.

Step 1: Check for Python Installation

1. Check whether python is installed in your server or not, by issuing below command.

# python –V 


# python  --version

It will show you the version of the python interpreter you’ve got and it will give you an error message if it is not installed.

Check Python Version

Check Python Version

2. You’re lucky if it was there by default. Less work actually. If it was not installed by any chance, install it following below commands.

If you have a SUSE distribution, type yast in the terminal –> Go to Software Management –> Type ‘python’ without quotes –> select python interpreter –> press space key and select it –> and then install it.

Simple as that. For that, you need to have SUSE ISO mounted and configured it as a repo by YaST or you can simple install python from the web.

Install Python on Suse

Install Python on Suse

If you’re using different operating systems like RHEL, CentOS, Debian, Ubuntu or other Linux operating systems, you can just install python using yum or apt.

In my case I use SLES 11 SP3 OS and python interpreter comes installed by default in it. Most of the case you won’t have to worry about installing python interpreter on your server.

Step 2: Create a Test Directory and Enable SimpleHTTPServer

3. Create a test directory where you don’t mess with system files. In my case I have a partition called /x01 and I have created a directory called tecmint in there and also I have added some test files for testing.

Create Testing Directory

Create Testing Directory

4. Your prerequisites are ready now. All you have to do is try python’s SimpleHTTPServer module by issuing below command within your test directory (In my case, /x01//).

# python –m SimpleHTTPServer
Enable SimpleHTTPServer

Enable SimpleHTTPServer

5. After enabling SimpleHTTPServer successfully, it will start serving files through port number 8000. You just have to open up a web browser and enter ip_address:port_number (in my case its

SimpleHTTPServer Directory Listing

Directory Listing

6. Now click on link 'tecmint' to browse files and directories of tecmint directory, see the screen below for reference.

Browse Directory Files

Browse Directory Files

7. SimpleHTTPServer serves your files successfully. You can see what has happened at the terminal, after you accessed your server through web browser by having a look at where you executed your command.

Python SimpleHTTPServer Status

Python SimpleHTTPServer Status

Step 3: Changing SimpleHTTPServer Port

8. By default python’s SimpleHTTPServer serves files and directories through port 8000, but you can define a different port number (Here I am using port 9999) as you desire with the python command as shown below.

# python –m SimpleHTTPServer 9999
Change SimpleHTTPServer Port

Change SimpleHTTPServer Port

Directory Listing on Different Port

Directory Listing on Different Port

Step 4: Serve Files from Different Location

9. Now as you tried it, you might like to serve your files in a specific location without actually going to the path.

As an example, if you are in your home directory and you want to server your files in /x01/tecmint/ directory without cd in to /x01/tecmint, Let’s see, how we will do this.

# pushd /x01/tecmint/; python –m SimpleHTTPServer 9999; popd;
Serve Files from Location

Serve Files from Location

Directory Listing on Different Port

Directory Listing on Different Port

Step 5: Serve HTML Files

10. If there’s a index.html file located in your serving location, python interpreter will automatically detect it and serve the html file instead of serving your files.

Let’s have a look at it. In my case I include a simple html script in the file named index.html and locate it in /x01/tecmint/.

<body text="blue"><H1>
Hi all. SimpleHTTPServer works fine.
<p><a href="">Visit TECMINT</a></p>
Create Index File

Create Index File

Now save it and run SimpleHTTPServer on /x01/tecmint and go to the location from a web browser.

# pushd /x01/tecmint/; python –m SimpleHTTPServer 9999; popd;
Enable Index Page

Enable Index Page

Serving Index Page

Serving Index Page

Very simple and handy. You can serve your files or your own html code in a snap. Best thing is you won’t have to worry about installing anything at all. In a scenario like you want to share a file with someone, you don’t have to copy the file to a shared location or making your directories shareable.

Just run SimpleHTTPServer on it and it is done. There is a few things you have to keep in mind when using this python module. When it serves files it runs on the terminal and prints out what happens in there. When you’re accessing it from the browser or download a file from it, it shows IP address accessed it and file downloaded etc. Very handy isn’t it?

If you want to stop serving, you will have to stop the running module by pressing ctrl+c. So now you know how to use python’s SimpleHTTPServer module as a quick solution to serve your files. Commenting below for the suggestions and new findings would be a great favour to enhance future articles and learn new things.

Reference Links

SimpleHTTPServer Docs

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Thilina Uvindasiri

I'm a BSc Special (Hons) graduate in Information Technology and works as an Engineer-Systems. Love to work, explore and research Linux and play rugby as a hobby.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

18 Responses

  1. Obaidulla says:

    Thanks a lot and like to see more python solution.

  2. Ahmad Amr says:


    Thanks, but do you know how to keep it running in the background? Whenever I log out of the ssh session, it cannot server again and gives 404 error!!

    • Ravi Saive says:

      Just add & string at the end of the command to keep the process running in background even after you logout from your SSH session. For example,

      # python –m SimpleHTTPServer &
      • Thilina Uvindasiri says:

        I don’t think that will work. If you ran the command by background and if you exit the terminal, it will get disconnected. Use below command instead. It will not disconnect the SimpleHTTPServer after you logout of the terminal.

        nohup python -m SimpleHTTPServer 9999 &

        Hope this will be useful

  3. Hi Uwe,
    Thanx for the correction :)

  4. Uwe says:

    Hi, Thilina, there is a typo under point 4. : “(In my case, /x01/tecmint/)”. That should be “(In my case, /x01/)” as can be seen in the picture below. Best, Uwe

  5. AlexSan says:

    Very helpful. Thanks :)

  6. Hi Setevoy,
    We’ll look in to your request and do the needful in the future. Thanx :)

  7. Hi Kumar, Thanx very much. :)

  8. setevoy says:

    WIll be nice to see same useful article about CGIHTTPServer.

  9. Parijatha Kumar says:

    Nice article. I know python-3 has a simple inbuilt http server and I have seen it’s uses in django while testing. However, using this technique for serving files on an ad hoc basis in your LAN in your office or home is one of the easiest ways. When all you want is to send a few files to other machines in your LAN, you need not worry about the OS of the other machines or how to configure SAMBA, NFS, SSH etc cause python’s built in http sever makes it trivial. You can even share files like this to your mobiles phones as well.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.