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

How To Create Python SimpleHTTPServer on ubuntu 18.04

2568

To Create Python SimpleHTTPServer on Ubuntu 18.04

SimpleHTTPServer is a python module that allows you to create a web server or serve your files in a snap instantly. The main benefit of python’ s SimpleHTTPServer is, you don’ t require to install anything if you have python interpreter already installed. This tutorial covers the method to create Python SimpleHTTPServer on Ubuntu 18.04.

Creating Python SimpleHTTPServer

Checking for Python Installation

By issuing the below command, you can check, whether python is installed on your server.

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

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

Create a Test Directory and Enable SimpleHTTPServer to create a directory for http web access. Create a directory which we want to access through web.

root@linuxhelp:~# cd /
root@linuxhelp:/# mkdir test
root@linuxhelp:/# cd test/
root@linuxhelp:/test# mkdir linux
root@linuxhelp:/test# cd linux/

After that, create some files to access through the http server.

root@linuxhelp:/test/linux# mkdir dir1 dir2
root@linuxhelp:/test/linux# touch file{1..9}
root@linuxhelp:/test/linux# ll
total 16
drwxr-xr-x 4 root root 4096 Apr 14 04:49 ./
drwxr-xr-x 3 root root 4096 Apr 14 04:48 ../
drwxr-xr-x 2 root root 4096 Apr 14 04:49 dir1/
drwxr-xr-x 2 root root 4096 Apr 14 04:49 dir2/
-rw-r--r-- 1 root root    0 Apr 14 04:49 file1
-rw-r--r-- 1 root root    0 Apr 14 04:49 file2
-rw-r--r-- 1 root root    0 Apr 14 04:49 file3
-rw-r--r-- 1 root root    0 Apr 14 04:49 file4
-rw-r--r-- 1 root root    0 Apr 14 04:49 file5
-rw-r--r-- 1 root root    0 Apr 14 04:49 file6
-rw-r--r-- 1 root root    0 Apr 14 04:49 file7
-rw-r--r-- 1 root root    0 Apr 14 04:49 file8
-rw-r--r-- 1 root root    0 Apr 14 04:49 file9

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

root@linuxhelp:/test/linux# python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
192.168.7.232 - - [14/Apr/2018 04:50:59] " GET / HTTP/1.1"  200 -
192.168.7.232 - - [14/Apr/2018 04:51:01] code 404, message File not found
192.168.7.232 - - [14/Apr/2018 04:51:01] " GET /favicon.ico HTTP/1.1"  404 -
192.168.7.232 - - [14/Apr/2018 04:51:01] code 404, message File not found
192.168.7.232 - - [14/Apr/2018 04:51:01] " GET /favicon.ico HTTP/1.1"  404 &ndash 

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

directory_listing

Let' s go one step back and launch the http server from that location

root@linuxhelp:/test/linux# cd ..
root@linuxhelp:/test# python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
192.168.7.232 - - [14/Apr/2018 04:51:46] " GET / HTTP/1.1"  200 -
192.168.7.232 - - [14/Apr/2018 04:51:49] " GET /linux/ HTTP/1.1"  200 -

Open up a web browser and type " http://< ip_address> :8000."

linux_dir

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.7.232 - - [14/Apr/2018 04:52:55] " GET / HTTP/1.1"  200 -
192.168.7.232 - - [14/Apr/2018 04:52:55] code 404, message File not found
192.168.7.232 - - [14/Apr/2018 04:52:55] " GET /favicon.ico HTTP/1.1"  404 -
192.168.7.232 - - [14/Apr/2018 04:52:55] code 404, message File not found
192.168.7.232 - - [14/Apr/2018 04:52:55] " GET /favicon.ico HTTP/1.1"  404 -
192.168.7.232 - - [14/Apr/2018 04:52:57] " GET /linux/ HTTP/1.1"  200 &ndash 

Open up a web browser and type " http://< ip_address> :9999"

port_number

To Serve Files from Different Location

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

root@linuxhelp:~# pwd
/home/user1
root@linuxhelp:~# cd /home/
root@linuxhelp:/home#
root@linuxhelp:/home# pushd /test/linux/  python -m SimpleHTTPServer 9999  popd /test/linux /home
/test/linux /home
Serving HTTP on 0.0.0.0 port 9999 ...
192.168.7.232 - - [14/Apr/2018 04:54:25] " GET / HTTP/1.1"  200 &ndash 

Now open up a web browser and type " http://< ip_address> :9999"

linux_directory

To Serve HTML Files

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

root@linuxhelp:/test/linux# vim index.html
root@linuxhelp:/test/linux# python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
192.168.7.232 - - [14/Apr/2018 04:56:11] " GET / HTTP/1.1"  200 -
192.168.7.232 - - [14/Apr/2018 04:56:52] " GET / HTTP/1.1"  200 &ndash 

Open up a web browser and type " http://< ip_address> :8000"

html_lists
With this, the method to Create Python SimpleHTTPServer on ubuntu 18.04 comes to an end.

Tags:
owen
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

Any alternative for SimpleHTTp server

A

Apache HTTP server, Nginx, Lighttpd, Cherokee, etc.,

Q

What is WSGI in Python?

A

The Web Server Gateway Interface (WSGI) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, version 1.0.1, is specified in Python Enhancement Proposal (PEP) 3333.

Q

What is python flask?

A

Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries.

Q

How to check server_version in python simplehttp server?

A

This will be "SimpleHTTP/" + __version__, where __version__ is defined at the module level.

Q

How do I use it Python SimpleHTTPServer?

A

To start a HTTP server on port 8000 (which is the default port), simple type:

python -m SimpleHTTPServer [port]

This will now show the files and directories which are in the current working
directory.

Related Tutorials in How To Create Python SimpleHTTPServer on ubuntu 18.04

Related Tutorials in How To Create Python SimpleHTTPServer on ubuntu 18.04

How to install Meld tool in Ubuntu
How to install Meld tool in Ubuntu
Feb 25, 2017
How to install Dconf-Editor on Ubuntu 18.04
How to install Dconf-Editor on Ubuntu 18.04
Jul 14, 2018
How to install and update OpenSSL on Ubuntu 16.04
How to install and update OpenSSL on Ubuntu 16.04
Mar 9, 2017
How to install GLib 2.0 on Ubuntu 17.04
How to install GLib 2.0 on Ubuntu 17.04
May 22, 2017
How to Install Android Emulator on Ubuntu 20.4.1
How to Install Android Emulator on Ubuntu 20.4.1
Jul 13, 2021
How To Install AnyDesk on Ubuntu 16.04
How To Install AnyDesk on Ubuntu 16.04
Apr 4, 2018
How to install Genymotion 2.12.1 on Ubuntu 18.04
How to install Genymotion 2.12.1 on Ubuntu 18.04
Jul 9, 2018
How to install Timeshift 18.4 on Ubuntu 18.04
How to install Timeshift 18.4 on Ubuntu 18.04
Jul 6, 2018

Related Forums in How To Create Python SimpleHTTPServer on ubuntu 18.04

Related Forums in How To Create Python SimpleHTTPServer on ubuntu 18.04

Web Server
jacob class=
How to remove httpd completely from server
Apr 7, 2017
Ubuntu
matthew class=
Failed to enable unit: Refusing to operate on linked unit file sshd.service
Apr 15, 2019
Ubuntu
mason class=
Passwd: You may not view or modify password information for root On Ubuntu 19.04
May 27, 2019
Ubuntu
isaac class=
/etc/apt/sources.list Permission denied
May 18, 2017
Ubuntu
yousuf class=
lsb_release command not working : Debian
Jan 18, 2018
ifconfig command
jackbrookes class=
what is the location of the ifconfig program on your machine?
Jan 4, 2018
Ubuntu
mason class=
"E: Package 'php-mcrypt' has no installation candidate" error on Ubuntu 20.4.1
Mar 15, 2021
NFS
luke class=
clnt_create: RPC: Program not registered
Apr 25, 2017

Related News in How To Create Python SimpleHTTPServer on ubuntu 18.04

Related News in How To Create Python SimpleHTTPServer on ubuntu 18.04

How To Install Mixxx on Ubuntu 16.04
How To Install Mixxx on Ubuntu 16.04
Oct 11, 2017
Ubuntu 17.04 released with greater expectations
Ubuntu 17.04 released with greater expectations
Apr 15, 2017
Ubuntu Core now available on i.MX6 based TS-4900 thanks to Technologic Systems Inc.
Ubuntu Core now available on i.MX6 based TS-4900 thanks to Technologic Systems Inc.
Mar 1, 2017
Ubuntu 17.10 Artful Aardvark Beta 1 is now here. Download Now
Ubuntu 17.10 Artful Aardvark Beta 1 is now here. Download Now
Sep 2, 2017
Ubuntu Unity is no more: One Linux dream has been axed
Ubuntu Unity is no more: One Linux dream has been axed
Apr 7, 2017
What’s next for Ubuntu Linux Desktop?
What’s next for Ubuntu Linux Desktop?
Apr 11, 2017
Say Hi to Ubuntu's new mascot
Say Hi to Ubuntu's new mascot
Mar 22, 2019
KDE Connect App was removed from Google Play Store and brought back in 24 hours
KDE Connect App was removed from Google Play Store and brought back in 24 hours
Mar 22, 2019
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.