How to set up PHP under AOLserver

From AOLserver Wiki
Jump to navigation Jump to search


  • AOLserver 4.0.6 [1] (currently CVS aolserver_v40_bp branch)
  • PHP 4.3.7 or 5.0.0 [2] + interim patch

Also works with AOLserver 4.0.10 and PHP 5.0.4 but has problems if multiple virtual hosts use PHP (crashes the nsd process on Solaris). This behavior is also documented on the mailinglist for PHP 4.x, so it is not a regression.


Step 1. Build and install Tcl and AOLserver.

You can use a binary distribution of Tcl provided it is a threaded build of Tcl. However, in order to build PHP, you will need to have AOLserver source available as PHP requires it in its own build process. These instructions assume that you will install AOLserver into "/home/aolserver" and the source resides in "/src/aolserver-4.0.5". Replace these to reflect your environment as necessary.

Building both Tcl and AOLserver is outside the scope of this document and should be covered in a separate document.

Step 2. Build and install PHP.

The following is an example of how you will need to configure PHP for building:

   $ ./configure  --with-aolserver=/home/aolserver --with-aolserver-src=/src/aolserver-4.0.5 --enable-shared

"--with-aolserver=/home/aolserver" is the path to where AOLserver is installed (the --prefix option when you build AOLserver) and "--with-aolserver-src=/src/aolserver-4.0.5" is the path to where the AOLserver source lives. "--enable-shared" may be turned on by default, which should build "" which we will need for AOLserver.

Once configured, run "make" to compile PHP. You do NOT need to do a "make install" or "make install-su" unless you want PHP to install the CLI executable and/or the PEAR stuff. To install the necessary bits for AOLserver, simply copy "libs/" for PHP 4.3.7 or "libs/" for PHP 5.0.0 to your AOLserver module directory, and "php.ini-recommended" to your AOLserver home directory as "php.ini".

   $ make
   ... lots of build output scrolls by ...
   $ cp libs/ /home/aolserver/bin
   $ cp php.ini-recommended /home/aolserver/php.ini

The default php.ini file should be suitable at first: customize and tweak it later once you've confirmed that PHP is indeed working correctly.

Step 3. Configure AOLserver to load PHP support.

Starting with the "sample-config.tcl" that comes with AOLserver, you need to make two simple changes. The first is to set (or increase) the stack size to a minimum of 256KB. The recommended value is 1MB. Here is the relevant snippet from the sample-config.tcl, lines 139-143:

   139 #
   140 # Thread library (nsthread) parameters
   141 #
   142 ns_section "ns/threads"
   143 #ns_param   stacksize expr 128*1024 ;# Per-thread stack size.

Note that the "ns_param" line that sets stack-size is currently commented out. Uncomment that line, and change it to:

   143 ns_param   stacksize expr 256*1024 ;# Per-thread stack size.

(Do not include the line number, "143", at the start of the line -- that is for illustrative purposes only.)

We have changed the stack from 128KB ("128*1024") to 256KB ("256*1024") and uncommented the line. Change it to "1024*1024" to set it to 1MB.

The next step is to add the necessary configuration to instruct AOLserver to load the PHP module at server start-up. We do this by adding the following lines to the bottom of the sample-config.tcl file:

   # PHP
   ns_section "ns/server/${servername}/module/php"
       ns_param map *.php
   ns_section "ns/server/${servername}/modules"
       ns_param php    ${bindir}/

This tells AOLserver to load our from the directory pointed to by $bindir, and indicates that files ending with the suffix ".php" contain PHP code and should be processed by the PHP module.

You will also want the server to look for PHP index pages. To do this, append "index.php" to the end of the directory file line in your AOLserver configuration file:

   set directoryfile   index.adp,index.html,index.htm,index.xhtml,index.xht,index.php

Step 4. Start AOLserver, and enjoy!

That's all there is to it. Start up your server, place some .php files in your pageroot (configured as "servers/server1/pages" by default in sample-config.tcl) and request them in a web browser. Everything should be working.

As of 22jun2004, phpBB2 2.0.8 [3] has been at least lightly tested. As of March 2007, SquirrelMail 1.4.3a [4] has undergone more thorough testing, and seems to work perfectly, but it is critical that the patch (see Appendix A below) has been installed!

Both phpBB2 and SquirrelMail store "sensitive" data that you probably don't want a user to browse. These come with .htaccess files installed but since AOLserver doesn't support .htaccess these files are unprotected. One option is to enable nsperm and create entries to grant access to a non-existent user (implicitly denying access to everyone else). The file to edit will live somewhere like "/home/aolserver/servers/server1/modules/nsperm/perms".

For phpBB2, add an entry like:

   allowuser inherit GET /phpBB2/cache notfound

For SquirrelMail, add an entry like:

   allowuser inherit GET /mail/data notfound
   allowuser inherit GET /mail/plugins/squirrelspell/modules notfound

There is nothing special about the user "notfound". Any string here that is not found in your nsperm "passwd" file will work. Change the URLs in the above examples to match the actual location of where you've installed the applications.

An alternative approach to explictly deny users access might look something like:

   denyuser inherit GET /mail/data ""

The downside of this second method is that it allows authenticated users (those users who are in the nsperm "passwd" file) to access these protected files.

Appendix A. Patch to PHP 4.3.7/5.0.0.

Before applying this patch, you may need to remove a single whitespace character from the beginning of every line (as they were added so that the patch appears as preformatted text on the wiki.) Place the file in the "php-4.3.7/sapi/aolserver" or "php-5.0.0/sapi/aolserver" directory as "aolserver.c.patch" and apply it with GNU patch:

   $ patch -p0 < aolserver.c.patch

Patch follows:

--- aolserver.c.orig    2003-05-30 21:37:44.000000000 -0400
+++ aolserver.c 2004-06-21 22:00:48.000000000 -0400
@@ -88,21 +88,12 @@
 static int
 php_ns_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
-       int n;
-       uint sent = 0;
-       while (str_length > 0) {
-               n = Ns_ConnWrite(NSG(conn), (void *) str, str_length);
-               if (n == -1)
-                       php_handle_aborted_connection();
-               str += n;
-               sent += n;
-               str_length -= n;
+    if (Ns_WriteConn(NSG(conn), str, str_length) != NS_OK) {
+        php_handle_aborted_connection();
+        return 0;
-       return sent;
+       return str_length;
@@ -148,7 +139,7 @@
 php_ns_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
        if(SG(sapi_headers).send_default_content_type) {
-               Ns_ConnSetRequiredHeaders(NSG(conn), "text/html", 0);
+               Ns_ConnSetRequiredHeaders(NSG(conn), "text/html", -1);
        Ns_ConnFlushHeaders(NSG(conn), SG(sapi_headers).http_response_code);

Appendix B. Testing with the PHP test cases.

PHP comes with a pretty thorough suite of test cases that check for regressions and for basic functionality. Many of these tests work in a webserver context as well (about 2/3 of them). A perl script,, can be used execute these tests. This script is not specific to AOLserver. It is known to work with Apache and should work with any webserver.

To test PHP:

  1. Download the script.
  2. Place the script in the PHP source tree.
  3. Execute: perl -h hostname:port -d /path/to/document/root

An example command line might look like:

   $ perl -h localhost:8000 -d /home/aolserver/servers/server1/pages/

This script has been tested with PHP 4.3.7 and PHP 5.0.0.

php-5.0.5 patch

--- aolserver.c 2005-09-14 22:18:03.000000000 -0400
+++ aolserver.c.back    2005-09-14 22:14:44.000000000 -0400
@@ -88,12 +88,21 @@
 static int
 php_ns_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
-        if (Ns_WriteConn(NSG(conn), str, str_length) != NS_OK) {
-            php_handle_aborted_connection();
-             return 0;
+       int n;
+       uint sent = 0;
+       while (str_length > 0) {
+               n = Ns_ConnWrite(NSG(conn), (void *) str, str_length);
+               if (n == -1)
+                       php_handle_aborted_connection();
+               str += n;
+               sent += n;
+               str_length -= n;
-       return str_length;
+       return sent;

@@ -139,7 +148,7 @@
 php_ns_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
        if(SG(sapi_headers).send_default_content_type) {
-               Ns_ConnSetRequiredHeaders(NSG(conn), "text/html", -1);
+               Ns_ConnSetRequiredHeaders(NSG(conn), "text/html", 0);

        Ns_ConnFlushHeaders(NSG(conn), SG(sapi_headers).http_response_code);


Category Documentation - Tutorials - PHP