[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#595163: PATCH to make php-cgi work with thttpd



Package: thttpd
Version: 2.25b-6
Severity: normal
Tags: patch

php-cgi needs SCRIPT_FILENAME environement variable to be defined to
detects it was invoqued as CGI script. It is not CGI compliant, but it
was writen like this. Here is a little patch which defines this
environment variable and take care of the TILDE_MAP_[12] preprocessor
definitions (in thttpd config.h), even if theses configuration variables
are undefined in Debian packages.

It also adds the index.php name to the index filename list to search for.

--- thttpd-2.25b.orig/config.h
+++ thttpd-2.25b/config.h
@@ -333,7 +333,7 @@
 /* CONFIGURE: A list of index filenames to check.  The files are searched
 ** for in this order.
 */
-#define INDEX_NAMES "index.html", "index.htm", "index.xhtml", "index.xht", "Default.htm", "index.cgi"
+#define INDEX_NAMES "index.php", "index.html", "index.htm", "index.xhtml", "index.xht", "Default.htm", "index.cgi"
 
 /* CONFIGURE: If this is defined then thttpd will automatically generate
 ** index pages for directories that don't have an explicit index file.
--- thttpd-2.25b.orig/libhttpd.c
+++ thttpd-2.25b/libhttpd.c
@@ -3045,6 +3045,13 @@
     envp[envn++] = build_env(
    "SCRIPT_NAME=/%s", strcmp( hc->origfilename, "." ) == 0 ?
    "" : hc->origfilename );
+    // PHP-CGI Support patch (Fanfan <francois@cerbelle.net>) : Begin
+    if ( hc->expnfilename[0] == '/' )
+        (void) my_snprintf(buf, sizeof(buf), "%s", strcmp( hc->expnfilename, "." ) == 0 ? "" : hc->expnfilename );
+    else
+        (void) my_snprintf(buf, sizeof(buf), "%s%s", hc->hs->cwd, strcmp( hc->expnfilename, "." ) == 0 ? "" : hc->expnfilename );
+    envp[envn++] = build_env("SCRIPT_FILENAME=%s", buf);
+    // PHP-CGI Support patch : End
     if ( hc->query[0] != '\0')
    envp[envn++] = build_env( "QUERY_STRING=%s", hc->query );
     envp[envn++] = build_env(

-- System Information:
Debian Release: 5.0.5
  APT prefers stable
  APT policy: (990, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-2-686 (SMP w/2 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash



Reply to: