One of the first things I do with any new PC is set up a web server on it - even on a netbook. I have (or had) an ugly combination of PHP and Perl which allowed me to set up lists of links, which can be updated through a web form. Having the dual-boot machine made me wonder about setting up the servers on the two operating systems to look at the same CGI and HTML directories. The first thing I did was to translate the Perl CGI script into Python, which is the programming language I'm most comfortable using these days.
I installed Apache 2.2.21 on Windows, then PHP 5.3.8 (many web pages say use the VC6-compiled version, I used the VC9 build, thread-safe version). The MSI install didn't work, I used the zip file to put it directly into C:\Program Files\PHP5. I then added these lines to Apache's httpd.conf file:
LoadModule php5_module "C:/Program Files/PHP5/php5apache2_2.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "C:/Program Files/PHP5"
With PHP now working, I fiddled around for a while trying to work out a way for the same Python CGI script to be run under both Windows and Linux. There is a way - described here.
- Keep the Linux "shebang line". This is the main problem - with scripts and interpreted programs, Unix systems use the first line of a file to determine what sort of thing it is, as opposed to the Windows method of using the file extension. Apache by default behaves that way even on Windows systems. The Linux shebang line is #!/usr/bin/python, and the Windows shebang line would be #!C:\Python27\python.exe - but you can't have both.
- In httpd.conf again, enter these lines:
SetEnv PYTHONUNBUFFERED 1
- Change the name of the script to include the .py extension (which should be already linked to Python).
I then decided that it was better to rewrite the whole thing in PHP, which made most of the above completely unnecessary.