Start Simple HTTP Server with Python


Please shareShare on Facebook3Share on Google+0Tweet about this on Twitter0Share on LinkedIn0Share on Reddit0Digg thisShare on StumbleUpon0Share on VKBuffer this page

This methode wil install the webserver in The same directory where you apply the python command.

The command will read automaticly the index.html page . if there is no index.html will list the contents of the directory .



So lets start

cd /var/www/html
[root@test11 html]# ls


[root@test11 html]# touch index.html
[root@test11 html]# view index.html

(make your Welcome text message)

[root@test11 html]# python -m SimpleHTTPServer

Serving HTTP on port 8000 … – – [23/Sep/2009 07:00:29] “GET / HTTP/1.1″ 200 –

Now open your browser with

http://localhost:8000 or or http://IP:8000


Other way you can change the web port with :

python -m SimpleHTTPServer 8081 or other  port

If you want to make your server local in your intern LAN of Only on this server edit this Pyhton script :


import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
HandlerClass = SimpleHTTPRequestHandler
ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"
if sys.argv[1:]:
port = int(sys.argv[1])
port = 8000
server_address = ('', port)
HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)

sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."