In the “scratch your own itch” department, I decided to get Wordpress working under AOLserver. Wordpress is written in PHP, and while AOLserver can load PHP as a module, it doesn’t play nice when you configure AOLserver with multiple virtual servers. The other option, running PHP as CGI using nscgi and php-cgi, does work for the most part. However, there were a few issues I ran into that required changes to nscgi, which I’ll outline below.
Adding REQUEST_URI to CGI env. variables
PHP expects an additional environment variable, REQUEST_URI, to be included on CGI requests. Of course, this isn’t part of the CGI/1.1 specification. Basically, PHP expects REQUEST_URI to contain the Request-URI (from the HTTP/1.1 specification, see section 5.1.2). So, I added this in.
Mapping URLs to CGI with ns_register_cgi
In order to map an URL to be handled by nscgi, you previously had to make the change in your config .tcl and restart AOLserver. One of the great things about AOLserver is the fact that you can modify some settings at runtime, without a restart. So, I looked at whether it would be possible to add additional mappings at runtime, and it appears that under the hood, nscgi also uses the Ns_RegisterRequest C API which is supposed to be safe to execute at runtime. So, I added a new Tcl command, ns_register_cgi, which is now part of nscgi. It is just a wrapper around CgiRegister, and thus takes the same argument.
For example, if you wanted to map all requests to “/foo” (including “/foo/bar“) to a PHP script “/var/www/myfoo.php“, you would use something like this:
foreach method {GET POST HEAD} {
ns_register_cgi "$method /foo /var/www/myfoo.php"
}
This maps GET, POST and HEAD requests to URLs starting with “/foo” to the script specified.
Caveat: It is currently possible to load the nscgi module multiple times in the same AOLserver process, for each virtual server. It is also possible to load it multiple times for the same virtual server. I’m not sure why anyone would do that, but it’s possible. In that circumstance, the behavior of ns_register_cgi is undefined–as in, I haven’t tested it. It may or may not work correctly. If you run such a configuration, where nscgi is loaded multiple times in the same virtual server, please test this carefully and share your findings. Thanks.
Where’s the code?
I’ve commited the changes to SourceForge CVS, both in HEAD (rev 1.33, diff) and the aolserver_v40_bp branch (rev 1.23.2.4, diff).








May 20th, 2009 at 7:47 pm
Hello Dossy, I'm coming back after some time still surprised with good news. Native Broadcom support in kernel (b43 driver) has ...
May 19th, 2009 at 10:16 pm
God conceived of–not literally “created”–everything at once but that some would only come to manifest at a certain point in ...
May 19th, 2009 at 7:53 pm
Hey Dossy your Twitter Karma tool is very nice, thank you for creating it. "Similarly, the pro-evolution arguers insisting that such ...
May 18th, 2009 at 10:49 am
Hello, The Electronic cigarette do not quit smoking, nothing replaces the will. However, it can replace some cigarettes daily and allows ...
May 17th, 2009 at 1:25 am
1 Corinthians 10:13 (New International Version) 13 No temptation has seized you except what is common to man. And God is ...