
All right, here it comes. I'm talking of Windows here. But the solution is applicable to other operating systems as well (if it's needed there at all ...). My advice is to install Python on your machine. This is just a matter of a few clicks once you have grabbed the complete installer package from the download page of python.org. Currently version 2.5.2 is what you should choose. It will propose to install to C:\Python25 which you should do. Make sure that this folder is added to your path. Installing Python isn't a danger or risk. It doesn't bloat your system and can be easiely removed using the uninstaller. But you'll never feel the need to do so.
Now create a folder as the root of your webserver and a subfolder where you put your documents. Let's say we now have ".../MyServer/htdocs". Create a file "MyServer/htdocs/helloworld.txt" with "Hello World!" as content. Open a command line window and navigate to the "MyServer/htdocs" folder. And one single command gets your web server on your local machine up and running:
C:\MyServer\htdocs> python -m CGIHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
WARNING: Do not start this server while you're connected to an untrustable net - like the internet - as it may expose your complete machine. Do local testing only!
What basically happens is that you start Python which will look for a python module CGIHTTPServer. The module will then be imported and as it finds out that it's running as a main module it activates "a little test routine" which will run forever until you press CTRL+C and the next http-request is encountered. The "little test routine" in fact is a complete webserver with some abilities. Do the test:
http://localhost:8000/helloworld.txt
and "Hello World!" is what you should see in the browser. You've tasted blood and would like to try some serverside active scripting? That's easy. Add a second folder named 'htdocs/cgi-bin' and place a little text file called "helloworld.py" there. It contains a single line:
print "Hello World!"
So now you have:
MyWebserver/ <- just to organize everything
MyWebserver/htdocs <- your webspace! start server here.
MyWebserver/htdocs/cgi-bin <- place Python scripts here
MyWebserver/htdocs/helloworld.txt
MyWebserver/htdocs/cgi-bin/helloworld.py
Now open this URL in your browser:
http://localhost:8000/cgi-bin/helloworld.py
You got this?

Python will start helloworld.py as a CGI-script and direct all output to your web page. Amazing, isn't it? There won't be PHP and MySQL unless they already existed on your machine. But Python programmers will now have hundreds of ideas of how to inspect and extend the code. You aren't a Python programmer? Well, become one! It's more than advisable!
extra key words: "poor man's web server"
Keine Kommentare:
Kommentar veröffentlichen