jbkc85
jbkc85

Reputation: 23

Setting up PHPFPM with Apache+mod_FastCGI

I recently took over a WebServer that is running PHP and Apache. PHP is currently utilizing PHPFPM through the mod_fastcgi of Apache. Everything is running fine, however during my research to make sure I understand the in-and-outs of the implementation, I have ran into a puzzling configuration. On the Apache WebServer, the following is used:

ScriptAlias /php-cgi "/usr/local/bin/php-cgi"    
AddHandler php-fastcgi .php    
Action php-fastcgi /php-cgi
FastCGIExternalServer /usr/local/bin/php-cgi -socket /tmp/php-fpm.sock -idle-timeout 60 -pass-header Authorization

Now, as mentioned before the above configuration works fine. But it would seem that this configuration is using TWO solutions - the PHP-CGI solution and PHP-FPM solution. From my readings and understanding, PHP-FPM offers a replacement for PHP-CGI, not something that runs along side it. Therefore, I am thinking the following configuration is supposed to be in place:

ScriptAlias /php-cgi "/usr/local/sbin/php-fpm"    
AddHandler php-fastcgi .php    
Action php-fastcgi /php-cgi
FastCGIExternalServer /usr/local/sbin/php-fpm -socket /tmp/php-fpm.sock -idle-timeout 60 -pass-header Authorization

The second configuration (using PHP-FPM) also works. I have not been able to notice anything between the two, but it concerns me that one or the other is effectively wrong.

Would anyone mind sharing their thoughts, findings, or answer which configuration is SUPPOSED to be in place? I don't like the idea of running php-cgi when I should be running php-fpm.

Thanks ahead of time, Jason

Upvotes: 2

Views: 2208

Answers (1)

user2591197
user2591197

Reputation: 43

You're looking at the wrong parameter. FastCGI uses the socket to communicate with PHP-FPM in this case. You will see the socket being configured in the PHP-FPM configuration.

So it's not the first parameter to FastCGIExternalServer that is important, but rather the second. The first is just there to fool Apache.

So what is happening with the handlers is that, a Handler is created for php, an Action is created for that Handler, that path is being aliased. When this is done FastCGI can point that path to a socket.

It'll be better in Apache 2.4 with mod_proxy_fcgi instead.

Cheers, Josef

Upvotes: 2

Related Questions