There are times that you want to test out a web script or page, but you don't want to install a resource hungry web server, or don't need to run a mySQL database or a server side script. IE: PHP, CGI, etc.
Here comes Python to the rescue. Python has a module to run a mini web server on your system. It takes no time to configure and eats up very little system resources! With the help of this little HTTP server you can turn any directory in your system into your web server directory. The only thing you need to have installed is Python, which is installed by default in PCLinuxOS.
Starting your Simple Server from the command line
Open up a terminal and go to the directory you would like to start the web server:
In my example I called mine "SimpleServer"
[dwmoar@laptop ~]$ cd SimpleServer
Now to start your Simple Server we enter
python -m SimpleHTTPServer
That's it! Now your http server will start using the default port 8000. You will see the following message in the terminal window
[dwmoar@laptop SimpleServer]$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000
If you want to run your Simple Server on another port you need to start it using the following format.
python -m SimpleHTTPServer port number
If I used python -m SimpleHTTPServer 8080
I would see the following.
[dwmoar@laptop SimpleServer]$ python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8080
Now open your favorite web browser and type the following address
http://localhost:8000 or http://127.0.0.1:8000 or using given port number that you chose to use.
If the directory has a file named "index.html," that file will be served as the initial file.
If there is no "index.html," then the files in the directory will be listed.
It even works using a public IP address:
To quit the Simple Server, in the console window use CTRL+C. This should also work on a Windows machine running Python. And there you go. Happy web serving!