Tuesday, November 8, 2011


The Department recently bought me a netbook - the HP Mini 110-3704sa (and a two gigabyte RAM upgrade). It came with Windows 7 Starter, which was removed within half an hour - it is now dual-booting Ubuntu Linux 11.10 and Windows 7 Professional.  I've had an older HP Mini (running only Linux) for a couple of years and found myself increasingly bringing it in to work because it was so useful.  I've been using the Windows installation more than I thought, mainly because of Office 2010 (not ideal, due to the "looking through a letterbox" screen dimensions, but usable - pop-up forms present a more serious problem, with the "Submit" button sometimes being off the bottom of the screen with no way to reach it other than tabbing through the fields and guessing when to stop).

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.

  1. 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.
  2. In httpd.conf again, enter these lines: 
    ScriptInterpreterSource registry

  3. 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.

No comments:

Post a Comment