php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54152 Make FPM compatible with Apache HTTP Server 2.3 mod_proxy_fcgi
Submitted: 2011-03-03 19:54 UTC Modified: 2011-03-29 13:39 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mark at catseye dot org Assigned: jimjag (profile)
Status: Closed Package: FPM related
PHP Version: 5.3SVN-2011-03-03 (snap) OS: Linux
Private report: No CVE-ID: None
 [2011-03-03 19:54 UTC] mark at catseye dot org
Description:
------------
Apache HTTP Server 2.3 is about to enter beta in preparation for a
general availability release of 2.4 soon, see:

http://marc.info/?l=apache-httpd-dev&m=129900037316343&w=2

Apache HTTP Server 2.3 comes with mod_proxy_fcgi as a standard module;
mod_fcgid and mod_fastcgi are not standard modules.  Unfortunately,
mod_proxy_fcgi and php-fpm do not work with each other.  One problem
is already being addressed on the Apache end:
http://marc.info/?l=apache-httpd-dev&m=129900037316343&w=2

There are two problems that, in my opinion, are best addressed
on the PHP end of things (patch attached).  php-fpm will then
work out of the box with mod_proxy_fcgi:

Problem 1:

PHP relies on the SCRIPT_FILENAME environment variable to find the script
to execute in the filesystem.  (It can also use SCRIPT_NAME for this, but
that will fail if the document root for php-fpm does not match the document
root of the httpd proxy).  In Apache HTTP Server 2.3, all proxy modules
prefix SCRIPT_FILENAME with "proxy:" followed by a protocol name, for
example, when the user requests

    https://server-name/test/test.php

Apache HTTP Server sets SCRIPT_FILENAME to

    proxy:fcgi://127.0.0.1:9000/www/php-ssl/test.php/extra/stuff

The attached patch causes php-fpm to recognize the "proxy:"
convention in this case, and skip over the subsequent protocol,
hostname and port.  In this example, SCRIPT_FILENAME then becomes

    /www/php-ssl/test.php/extra/stuff

...which php-fpm is able to deal with correctly.

I believe that PHP is the correct place to change this, rather than in
Apache HTTP Server, since the proxy (httpd) and origin (php-fpm, in this
case) may be on different servers machine and httpd should not make
assumptions about the origin's document root or URI path namespace mapping.


Problem 2:

Apache HTTP Server is not able to set a value for PATH_INFO and still
comply with RFC 3875, for the reasons in the last paragraph above.

sapi/fpm/fpm/fpm_main.c:init_request_info() will find the base script
using SCRIPT_FILENAME, but uses this to calculate and offset into the
original PATH_INFO environment variable.  Since no such environment
variable exists (if the patch to Apache HTTP Server is applied),


Additional notes:

Except for 21 additional lines in the fpm version, the code in
init_request_info() is duplicated in the following two files
(378 identical lines in the two versions of this one function):

sapi/fpm/fpm/fpm_main.c
sapi/cgi/cgi_main.c

The changes in the attached patch are made to both files.  While
they are only really needed in sapi/fpm/fpm/fpm_main.c, making the
changes in both places should do no harm, will permit the cgi sapi
to be used more flexibly, and be more consistent overall by
minimizing special cases.

----

Using php5.3-201103031330 snapshot.
no changes to php.ini

Fedora 14, 64-bit (fully patched)
gcc 4.5.1

./configure --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --cache-file=../config.cache --with-libdir=lib64 --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --disable-debug --with-pic --disable-rpath --without-pear --with-bz2 --with-exec-dir=/usr/bin --with-freetype-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr --enable-gd-native-ttf --with-t1lib=/usr --without-gdbm --with-gettext --with-gmp --with-iconv --with-jpeg-dir=/usr --with-openssl --with-pcre-regex=/usr --with-zlib --with-layout=GNU --enable-exif --enable-ftp --enable-magic-quotes --enable-sockets --with-kerberos --enable-ucd-snmp-hack --enable-shmop --enable-calendar --without-sqlite --with-libxml-dir=/usr --enable-xml --with-system-tzdata --enable-force-cgi-redirect --enable-pcntl --with-imap=shared --with-imap-ssl --enable-mbstring=shared --enable-mbregex --with-gd=shared --enable-bcmath=shared --enable-dba=shared --with-db4=/usr --with-xmlrpc=shared --with-ldap=shared --with-ldap-sasl --with-mysql=shared,/usr --with-mysqli=shared,/usr/lib64/mysql/mysql_config --with-interbase=shared,/usr/lib64/firebird --with-pdo-firebird=shared,/usr/lib64/firebird --enable-dom=shared --with-pgsql=shared --enable-wddx=shared --with-snmp=shared,/usr --enable-soap=shared --with-xsl=shared,/usr --enable-xmlreader=shared --enable-xmlwriter=shared --with-curl=shared,/usr --enable-fastcgi --enable-pdo=shared --with-pdo-odbc=shared,unixODBC,/usr --with-pdo-mysql=shared,/usr/lib64/mysql/mysql_config --with-pdo-pgsql=shared,/usr --with-pdo-sqlite=shared,/usr --with-pdo-dblib=shared,/usr --with-sqlite3=shared,/usr --enable-json=shared --enable-zip=shared --without-readline --with-libedit --with-pspell=shared --enable-phar=shared --with-mcrypt=shared,/usr --with-tidy=shared,/usr --with-mssql=shared,/usr --enable-sysvmsg=shared --enable-sysvshm=shared --enable-sysvsem=shared --enable-posix=shared --with-unixODBC=shared,/usr --enable-fileinfo=shared --enable-intl=shared --with-icu-dir=/usr --with-enchant=shared,/usr --with-recode=shared,/usr --enable-fpm


Test script:
---------------
<html>
  <head> <title>php-fpm test</title> </head>
  <body> <?php phpinfo(); ?> </body>
</html>


Expected result:
----------------
1. Save the script in the file file /www/php-ssl/test.php

2. Build Apache HTTP Server 2.3.10 alpha with the patch in

https://issues.apache.org/bugzilla/show_bug.cgi?id=50851

(Note: without the patch to httpd, httpd sets PATH_INFO incorrectly, which
makes the result from php-fpm incorrect with or without the patch to PHP
included in this PHP bug report).

3. Configure httpd to act as a reverse proxy for php-fpm by adding the following to httpd.conf:

ProxyPass /test/ fcgi://127.0.0.1:9000/www/php-ssl/

4. Run the script by requesting:

https://server-name/test/test.php/extra/stuff

The script executes, producing a phpinfo() page.  In the "PHP Variables"
section of the page, the following are expected after the attached patch
is applied:

_SERVER["SCRIPT_FILENAME"]      /www/php-ssl/test.php
_SERVER["REQUEST_URI"]          /test/test.php/extra/stuff
_SERVER["PATH_INFO"]            /extra/stuff
_SERVER["PATH_TRANSLATED"]      /www/html-ssl/extra/stuff
_SERVER["ORIG_SCRIPT_FILENAME"] /www/php-ssl/test.php/extra/stuff



Actual result:
--------------
php-fpm returns a HTTP 404 (Not Found) response to the Apache HTTP Server
proxy.


Patches

mod_proxy_fcgi-support-v3.patch (last revision 2011-03-07 18:49 UTC by jimjag@php.net)
mod_proxy_fcgi-support-v2.patch (last revision 2011-03-07 17:37 UTC by mark at catseye dot org)
mod_proxy_fcgi-support.patch (last revision 2011-03-03 18:56 UTC by mark at catseye dot org)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-03 20:35 UTC] mark at catseye dot org
The second URL is incorrect; apologies for the mistake.  The correct URL for the problem that is being addressed on the Apache end is:

https://issues.apache.org/bugzilla/show_bug.cgi?id=50851
 [2011-03-04 23:55 UTC] mark at catseye dot org
The problem on the Apache HTTP Server end between mod_proxy_fcgi and php-fpm has been addressed, and the solution will be in the second beta of Apache HTTP Server 2.4, which will be version 2.3.12 (the first beta, 2.3.11, will be released Monday March 7th).

https://issues.apache.org/bugzilla/show_bug.cgi?id=50851
 [2011-03-07 17:24 UTC] jimjag@php.net
-Assigned To: +Assigned To: jimjag
 [2011-03-07 17:24 UTC] jimjag@php.net
My preference would be to simply add this to the fpm/FastCGI code path, since this 
is solely due to how Apache handles that protocol. Also folding into the cgi path 
unnecessary muddies things, imo.
 [2011-03-07 18:40 UTC] mark at catseye dot org
jimjag, I've attached version 2 of the patch ( mod_proxy_fcgi-support-v2.patch ) which changes only the FPM/FastCGI code path and leaves the CGI code path unmodified.

Thanks for your time on this!
 [2011-03-07 19:49 UTC] jimjag@php.net
The following patch has been added/updated:

Patch Name: mod_proxy_fcgi-support-v3.patch
Revision:   1299523794
URL:        http://bugs.php.net/patch-display.php?bug=54152&patch=mod_proxy_fcgi-support-v3.patch&revision=1299523794
 [2011-03-07 19:50 UTC] jimjag@php.net
please try v3 of the patch... This limits the later on version of the changes to 
just be in effect when we know we're handling the proxy:fcgi:// stuff
 [2011-03-09 18:56 UTC] mark at catseye dot org
Tested v3 of the patch against development snapshot php5.3-201103091530.  Verified that the script gets executed, SCRIPT_FILENAME is set correctly, PATH_INFO is set correctly, and the php-fpm status page works.  Compared output of phpinfo() between version 2 and version 3 of the patch for requests with extra-path components and query strings; did not find any discrepancies.  Reviewed the patch itself and it looks good.
 [2011-03-09 19:27 UTC] jimjag@php.net
Automatic comment from SVN on behalf of jimjag
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=309053
Log: Close [PHP-BUG] Req #54152...
Apache 2.3.12 (and later) will now work correctly with PHP's fcgi
impl with this patch.
 [2011-03-09 19:53 UTC] jimjag@php.net
Automatic comment from SVN on behalf of jimjag
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=309054
Log: Close [PHP-BUG] Req #54152...
Apache 2.3.12 (and later) will now work correctly with PHP's fcgi
impl with this patch.
 [2011-03-29 13:39 UTC] mark at catseye dot org
-Status: Assigned +Status: Closed
 [2011-03-29 13:39 UTC] mark at catseye dot org
v3 of the patch was applied to trunk in r309054

http://svn.php.net/viewvc?view=revision&revision=309054
 [2011-09-15 19:08 UTC] apache-lists at riggs dot me
This fix does not take into account using mod_proxy_balancer. When I use this 
same setup using mod_proxy_fcgi as a BalancerMember, I get a SCRIPT_FILENAME of 
proxy:balancer://.... Should this be reopened to handle that, or should we create 
a new bug?
 [2011-09-15 19:09 UTC] fat@php.net
reopen :)
 [2013-03-01 15:48 UTC] phpfpm1 at gmail dot com
Any news on the subject?
 [2014-05-06 11:12 UTC] jimjag@php.net
Please reopen or create a new bug report.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC