af9dc8
From ee275e34c8b303945945c650d4bc90dcc2ac0b17 Mon Sep 17 00:00:00 2001
af9dc8
From: David Zuelke <dzuelke@gmail.com>
af9dc8
Date: Sat, 9 Aug 2014 08:26:33 +0200
af9dc8
Subject: [PATCH] restore FPM compatibility with mod_fastcgi broken since #694
af9dc8
 / 67541, fixes bug 67606
af9dc8
af9dc8
---
af9dc8
 sapi/fpm/fpm/fpm_main.c | 11 ++++++++---
af9dc8
 1 file changed, 8 insertions(+), 3 deletions(-)
af9dc8
af9dc8
diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c
af9dc8
index e879325..56a06f9 100644
af9dc8
--- a/sapi/fpm/fpm/fpm_main.c
af9dc8
+++ b/sapi/fpm/fpm/fpm_main.c
af9dc8
@@ -1142,13 +1142,16 @@ static void init_request_info(TSRMLS_D)
af9dc8
 				TRANSLATE_SLASHES(env_document_root);
af9dc8
 			}
af9dc8
 
af9dc8
-			if (env_path_translated != NULL && env_redirect_url != NULL &&
af9dc8
+			if (!apache_was_here && env_path_translated != NULL && env_redirect_url != NULL &&
af9dc8
 			    env_path_translated != script_path_translated &&
af9dc8
 			    strcmp(env_path_translated, script_path_translated) != 0) {
af9dc8
 				/*
af9dc8
 				 * pretty much apache specific.  If we have a redirect_url
af9dc8
 				 * then our script_filename and script_name point to the
af9dc8
 				 * php executable
af9dc8
+				 * we don't want to do this for the new mod_proxy_fcgi approach,
af9dc8
+				 * where redirect_url may also exist but the below will break
af9dc8
+				 * with rewrites to PATH_INFO, hence the !apache_was_here check
af9dc8
 				 */
af9dc8
 				script_path_translated = env_path_translated;
af9dc8
 				/* we correct SCRIPT_NAME now in case we don't have PATH_INFO */
af9dc8
@@ -1323,7 +1326,7 @@ static void init_request_info(TSRMLS_D)
af9dc8
 					efree(pt);
af9dc8
 				}
af9dc8
 			} else {
af9dc8
-				/* make sure path_info/translated are empty */
af9dc8
+				/* make sure original values are remembered in ORIG_ copies if we've changed them */
af9dc8
 				if (!orig_script_filename ||
af9dc8
 					(script_path_translated != orig_script_filename &&
af9dc8
 					strcmp(script_path_translated, orig_script_filename) != 0)) {
af9dc8
@@ -1332,7 +1335,9 @@ static void init_request_info(TSRMLS_D)
af9dc8
 					}
af9dc8
 					script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", script_path_translated TSRMLS_CC);
af9dc8
 				}
af9dc8
-				if (env_redirect_url) {
af9dc8
+				if (!apache_was_here && env_redirect_url) {
af9dc8
+					/* if we used PATH_TRANSLATED to work around Apache mod_fastcgi (but not mod_proxy_fcgi,
af9dc8
+					 * hence !apache_was_here) weirdness, strip info accordingly */
af9dc8
 					if (orig_path_info) {
af9dc8
 						_sapi_cgibin_putenv("ORIG_PATH_INFO", orig_path_info TSRMLS_CC);
af9dc8
 						_sapi_cgibin_putenv("PATH_INFO", NULL TSRMLS_CC);
af9dc8
-- 
af9dc8
2.1.4
af9dc8
af9dc8
From 8cac75969e5abb2b6be5bbd489d851a4f9e50979 Mon Sep 17 00:00:00 2001
af9dc8
From: Remi Collet <remi@php.net>
af9dc8
Date: Mon, 15 Sep 2014 13:29:55 +0200
af9dc8
Subject: [PATCH] Fixed bug #65641 PHP-FPM incorrectly defines the SCRIPT_NAME
af9dc8
 variable when using Apache
af9dc8
af9dc8
ProxyPass is unable to provide correct PATH_INFO
af9dc8
as it is not aware of file path (while SetHandler is).
af9dc8
af9dc8
As we can extract PATH_INFO from PATH_TRANSLATED,
af9dc8
we also need to check if present in SCRIPT_NAME
af9dc8
and remove it.
af9dc8
af9dc8
After applying this patch.
af9dc8
With mod_php
af9dc8
_SERVER["REQUEST_URI"]     /info.php/foo/bar?q=1
af9dc8
_SERVER["SCRIPT_NAME"]     /info.php
af9dc8
_SERVER["PATH_INFO"]       /foor/bar
af9dc8
_SERVER["PHP_SELF"]        /info.php/foo/bar
af9dc8
_SERVER["QUERY_STRING"]    q=1
af9dc8
af9dc8
With mod_proxy_fcgi + SetHandler
af9dc8
_SERVER["REQUEST_URI"]     /info.php/foo/bar?q=1
af9dc8
_SERVER["SCRIPT_NAME"]     /info.php
af9dc8
_SERVER["PATH_INFO"]       /foo/bar
af9dc8
_SERVER["PHP_SELF"]        /info.php/foo/bar
af9dc8
_SERVER["QUERY_STRING"]    q=1
af9dc8
af9dc8
With mod_proxy_fcgi + ProxyPass
af9dc8
_SERVER["REQUEST_URI"]     /info.php/foo/bar?q=1
af9dc8
_SERVER["SCRIPT_NAME"]     /info.php
af9dc8
_SERVER["PATH_INFO"]       /foo/bar
af9dc8
_SERVER["PHP_SELF"]        /info.php/foo/bar
af9dc8
_SERVER["QUERY_STRING"]    q=1
af9dc8
---
af9dc8
 sapi/fpm/fpm/fpm_main.c | 11 +++++++++++
af9dc8
 1 file changed, 11 insertions(+)
af9dc8
af9dc8
diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c
af9dc8
index 56a06f9..331342c 100644
af9dc8
--- a/sapi/fpm/fpm/fpm_main.c
af9dc8
+++ b/sapi/fpm/fpm/fpm_main.c
af9dc8
@@ -1231,6 +1231,17 @@ static void init_request_info(TSRMLS_D)
af9dc8
 										SG(request_info).request_uri = orig_script_name;
af9dc8
 									}
af9dc8
 									path_info[0] = old;
af9dc8
+								} else if (apache_was_here && env_script_name) {
af9dc8
+									/* Using mod_proxy_fcgi and ProxyPass, apache cannot set PATH_INFO
af9dc8
+									 * As we can extract PATH_INFO from PATH_TRANSLATED
af9dc8
+									 * it is probably also in SCRIPT_NAME and need to be removed
af9dc8
+									 */
af9dc8
+									int snlen = strlen(env_script_name);
af9dc8
+									if (snlen>slen && !strcmp(env_script_name+snlen-slen, path_info)) {
af9dc8
+										_sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC);
af9dc8
+										env_script_name[snlen-slen] = 0;
af9dc8
+										SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name TSRMLS_CC);
af9dc8
+									}
af9dc8
 								}
af9dc8
 								env_path_info = _sapi_cgibin_putenv("PATH_INFO", path_info TSRMLS_CC);
af9dc8
 							}
af9dc8
-- 
af9dc8
2.1.4
af9dc8