• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to Create Webserver- Python 'SimpleHTTPServer'

994

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

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."

Related Tutorials in How to Create Webserver- Python 'SimpleHTTPServer'

Related Tutorials in How to Create Webserver- Python 'SimpleHTTPServer'

How To Create Python SimpleHTTPServer on ubuntu 18.04
How To Create Python SimpleHTTPServer on ubuntu 18.04
Jun 9, 2018
How to Install Python Anaconda in ubuntu 16.04
How to Install Python Anaconda in ubuntu 16.04
Feb 14, 2018
How to Create Webserver- Python 'SimpleHTTPServer'
How to Create Webserver- Python 'SimpleHTTPServer'
Jun 8, 2016
How to install Python V 3.6.5 on Centos 7
How to install Python V 3.6.5 on Centos 7
Oct 23, 2018
How to install ampps web server in Ubuntu
How to install ampps web server in Ubuntu
Jul 14, 2016
How to install python server on CentOS 7
How to install python server on CentOS 7
Aug 11, 2017
How To Install Sublime Text Editor In Linux
How To Install Sublime Text Editor In Linux
Jul 9, 2016
How to install OpenCV with python on CentOS7
How to install OpenCV with python on CentOS7
Sep 4, 2018

Related Forums in How to Create Webserver- Python 'SimpleHTTPServer'

Related Forums in How to Create Webserver- Python 'SimpleHTTPServer'

Python
jacob class=
Downgrade the Python version from Python 3.6.8 to python 2.7.5 default Version
Dec 17, 2019
Python
joshwariddin class=
Facing - pip error while installing Python: Ignoring ensurepip failure: pip 8.1.1 requires SSL/TLS
Sep 29, 2018
Ubuntu
keshavadk class=
FTP and SFTP server using Python
Apr 21, 2020
Python
carter class=
Cant able to view output in browser - python simpleHTTPServer
Apr 7, 2017
Linux
gabriel class=
pip command not found error
May 2, 2017
Python
jacob class=
Ansible “ansible_python_interpreter” Error
Oct 30, 2021
Python
rebeccajazz class=
set the default python version
Sep 29, 2018
Apache
lawrence class=
how to execute python application in apache
Sep 27, 2017
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 Sebastian ?
How to change non required to required field in SuiteCRM Custom/Default Modules

How to change not required to the required field in SuiteCRM Custom/Default Modules?

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.