• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to Create Webserver- Python 'SimpleHTTPServer'

{{postValue.id}}

To Create Webserver- Python ‘ SimpleHTTPServer’

SimpleHTTPServer is a python module that allows you to create a web server or serve your files in a snap instantly. Main benefit of python’ s SimpleHTTPServer is, you don’ t require to install anything if you have python interpreter already installed. Use of Python ‘ SimpleHTTPServer’ to Create Webserver or Serve Files Instantly is explained in this article.

Checking for Python Installation

By issuing the below command, check whether python is installed in your server.

root@linuxhelp:~# python --version
Python 2.7.11+


Install python using yum or apt-get, if using operating systems like RHEL, CentOS, Debian, Ubuntu or other Linux operating systems.

To Create a Test Directory and Enable SimpleHTTPServer

Now let us create a directory for http web access.

root@linuxhelp:/test# mkdir linux
root@linuxhelp:/test# cd linux/
root@linuxhelp:/test/linux# mkdir dir1 dir2
root@linuxhelp:/test/linux# touch file{1..10}
root@linuxhelp:/test/linux# ls
dir1  file1   file2  file4  file6  file8
dir2  file10  file3  file5  file7  file9
root@linuxhelp:/test/linux# cd ..


Try python’ s SimpleHTTP Server module by running below command within test directory.

root@linuxhelp:/test# python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...

After enabling SimpleHTTPServer, it will automatically start serving files via port number 8000. Now open up a web browser and type " ip_address:port_number" .


Linux client
1

Windows client
2

Click on link ' linux' to browse files and directories in the linux directory.
3

SimpleHTTPServer serves files successfully. After access your server via browser, look at the terminal where you have executed your command.

root@linuxhelp:/test# python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
192.168.5.183 - - [14/May/2016 14:15:24] " GET / HTTP/1.1"  200 -
192.168.5.183 - - [14/May/2016 14:15:25] code 404, message File not found
192.168.5.183 - - [14/May/2016 14:15:25] " GET /favicon.ico HTTP/1.1"  404 -
192.168.5.183 - - [14/May/2016 14:15:25] code 404, message File not found
192.168.5.183 - - [14/May/2016 14:15:25] " GET /favicon.ico HTTP/1.1"  404 -
192.168.5.183 - - [14/May/2016 14:18:06] " GET / HTTP/1.1"  200 -
192.168.5.183 - - [14/May/2016 14:18:21] " GET /linux/ HTTP/1.1"  200 -
192.168.5.11 - - [14/May/2016 14:20:41] " GET / HTTP/1.1"  200 -
192.168.5.11 - - [14/May/2016 14:20:41] code 404, message File not found
192.168.5.11 - - [14/May/2016 14:20:41] " GET /favicon.ico HTTP/1.1"  404 -
192.168.5.11 - - [14/May/2016 14:20:41] code 404, message File not found
192.168.5.11 - - [14/May/2016 14:20:41] " GET /favicon.ico HTTP/1.1"  404 -
192.168.5.11 - - [14/May/2016 14:20:48] " GET /linux/ HTTP/1.1"  200 -

To Change SimpleHTTPServer Port

Python’ s SimpleHTTPServer serves files and directories via port 8000 by default, to define a different port number use the following command.

root@linuxhelp:/test# python -m SimpleHTTPServer 9999
Serving HTTP on 0.0.0.0 port 9999 ...
192.168.5.183 - - [14/May/2016 14:30:18] " GET / HTTP/1.1"  200 -
192.168.5.183 - - [14/May/2016 14:30:18] code 404, message File not found
192.168.5.183 - - [14/May/2016 14:30:18] " GET /favicon.ico HTTP/1.1"  404 -
192.168.5.183 - - [14/May/2016 14:30:18] code 404, message File not found
192.168.5.183 - - [14/May/2016 14:30:18] " GET /favicon.ico HTTP/1.1"  404 -
192.168.5.183 - - [14/May/2016 14:30:53] " GET /linux/ HTTP/1.1"  200 -
192.168.5.11 - - [14/May/2016 14:31:31] " GET / HTTP/1.1"  200 -
192.168.5.11 - - [14/May/2016 14:31:31] code 404, message File not found
192.168.5.11 - - [14/May/2016 14:31:31] " GET /favicon.ico HTTP/1.1"  404 -
192.168.5.11 - - [14/May/2016 14:31:31] code 404, message File not found
192.168.5.11 - - [14/May/2016 14:31:31] " GET /favicon.ico HTTP/1.1"  404 -
192.168.5.11 - - [14/May/2016 14:31:42] " GET /linux/ HTTP/1.1"  200 -
192.168.5.11 - - [14/May/2016 14:31:49] " GET /linux/ HTTP/1.1"  200 -


Linux client
4

Windows client
5

To Serve Files from Different Location

To serve files in a specific location without going to the path, use the following command.



root@linuxhelp:/home# pushd /test/linux/  python -m SimpleHTTPServer 9999  popd /test/linux /home
Serving HTTP on 0.0.0.0 port 9999 ...


Linux client
7

Windows client
6

To Serve HTML Files

Open index.html file in your serving location, and add the following entries.

< html> 
< head> < title>  Welcome to Linuxhelp.com < /title> 
< /head> 
< body> 
< h5>  Welcome To Linuxhelp.com < /h5> 
< h4>  Welcome To Linuxhelp.com < /h4> 
< h3>  Welcome To Linuxhelp.com < /h3
< /body> 
< /html> 


Save the file and run the SimpleHTTPServer.

root@linuxhelp:/home# cd /test/linux/
root@linuxhelp:~# pushd /test/linux/  python -m SimpleHTTPServer 9999  popd 
/test/linux ~
Serving HTTP on 0.0.0.0 port 9999 ...


Linux client
8

Windows client
9

Tags:
mason
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

Is it possible to access the SimpleHTTPServer from outside the LAN, like over DNS?

A

As far as you’ve static IP address, you can access SimpleHTTPServer from anywhere in the world using IP address and port

Q

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!!

A

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 &

Q

What was its essential property of FlevExtract?

A

Flvextract is an extracting tool that extracts the audio and video files from FLV files and can also remux to MP4 or MKV without converting it

Q

What was its official website to look for updates of flvextract-python

A

The official website for flvextract-python is http://www.moitah.net/.

Q

What is the option for extracting timecodes in Flvextract?

A

option for extracting timecodes in Flvextract is "-tExtract timecodes."

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Ryan ?
how to use visual traceroute tool

Am using traceroute command to check for the route. i got this tool while surfing. So pls help me out installation and usage of Visual traceroute tool.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.