Start Simple HTTP Server with Python

by

Please shareShare on Facebook0Share 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

info.php

[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 0.0.0.0 port 8000 …

Test11.unixmen.com – – [23/Sep/2009 07:00:29] “GET / HTTP/1.1″ 200 –

Now open your browser with

http://localhost:8000 or http://127.0.0.1 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])
else:
port = 8000
server_address = ('127.0.0.1', port)
HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)

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

 

Enjoy