Re: Fixing (and making easier) Apache mod_proxy_fcgi with PHP-FPM
| From: | David Zuelke | Date: | Sat, 14 Jun 2014 12:34:29 +0000 |
| Subject: | Re: Fixing (and making easier) Apache mod_proxy_fcgi with PHP-FPM | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-74902@lists.php.net to get a copy of this message | ||
On 14.06.2014, at 06:57, David Muir <davidkmuir@gmail.com> wrote:
> On 13 Jun 2014, at 5:47 am, David Zuelke <dz@heroku.com> wrote:
>
>> The new approach, which can also be built as a standalone module for older versions of
>> Apache (https://gist.github.com/progandy/6ed4eeea60f6277c3e39), works like this:
>>
>> <FilesMatch \.php$>
>> SetHandler proxy:fcgi://localhost:9000
>> </FilesMatch>
>>
>> It's very simple, and very similar to how mod_php is used in Apache, so that'll
>> make it very easy and convenient for users to use FPM with Apache 2.4.10+
>
>
> This sounds great! And I see in the comments on github that it works with unix sockets too! I
> just wasted several hours trying to get my user-land rewrites working... I had to swap to using a
> RewriteRule instead of ProxyPassMatch, but I could not get it working with a unix socket. In the end
> I had to reconfigure FPM to listen to a tcp socket instead. Very annoying, but I’m very happy to
> see a much simpler and cleaner solution just around the corner! Hopefully I’ll actually be able to
> start using 5.5 in production soon.
You can use UDS too; you just have to trick Apache into creating proxy instances first:
<Proxy "unix:/tmp/php-fpm.sock|fcgi://php-fpm">
# we must declare a parameter in here (doesn't matter which) or it'll not register the
proxy ahead of time
ProxySet disablereuse=off
</Proxy>
<FilesMatch \.php$>
SetHandler proxy:fcgi://php-fpm
</FilesMatch>
This basically creates an alias to the UDS under whatever name you give it after
"fcgi://", and you can reference that in SetHandler, rewrites or ProxyPass(Match). Apache
will pass "proxy:fcgi://php-fpm:8000" (no idea why it picks that port) as the prefix to
the backend in this case.
The better solution of course would be if FPM supported the unix domain socket syntax in
SCRIPT_FILENAME et al (which will then look like proxy:unix:/tmp/php-fpm.sock|fcgi://php-fpm, so
it'll need to "regex-strip" ^proxy:unix:[^|]+|fcgi:// instead of the static
proxy:fcgi:// prefix that it strips now.
Anyone want to take a stab at fixing that? Line ~1100 in fpm_main.c :)
David