FastCGIExternalServer demystified

« 1 2 3 4 5 6 7 8 9View All»

Last Fixups

The remaining problem is that PHP has a little issue with translating the path information it gets when running as an FCGI server. This results in

$_SERVER['SCRIPT_NAME']

being set to a wrong value. To fix this, we unfortunately have to patch PHP itself, namely the file

sapi/cgi/cgi_main.c

. There, after line 976, add this:

if (env_redirect_url &&
	strncmp(env_server_software, "Apache", sizeof("Apache")-1) == 0) {
	/*
	 * If we have an env_redirect_url and the web server is Apache
	 * it's very likely that env_redirect_url is the one we really
	 * want
	 */
	env_script_name = env_redirect_url;
}

This will make sure that the superglobal variable is set to the right value when using Apache 2.2 as your FastCGI frontend server. The patch has been tested with PHP 5.2.9 and 5.2.10 but might work with other versions as well.

Incoming search terms:

This entry was posted in PHP, Software, the ugly truth and tagged , , . Bookmark the permalink.

3 Responses to FastCGIExternalServer demystified

  1. Pingback: External FastCGI With Apache « IT Know-It-All

  2. Mattes says:

    Great article, but how did you solve the problem with the trailing index.php?
    If I call the domain, the php file are provided as a download.
    If I add index.php, I get redirected to /virtualpath/index.php/ which results in a 404. Everything else works like a charm…

  3. Stefan Rubner says:

    Can’t really say what the problem with your setup is. Either it’s a missing “DirectoryIndex index.php” statement in the htpd.conf file or your settings for calling the FCGI process are a bit borked. If you could post the settings for your vhost, maybe I could help more then.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>