Saturday, December 22, 2018

apache 2.2 - Why the php-cgi wrapper script for php-fpm? (Using virtualhost and suexec.)

I just setup my server with Apache, FastCGI, and PHP-FPM. My question is regarding the /cgi-bin/ folder: is it really necessary to have a /cgi-bin/php-fpm wrapper for every single virtualhost that runs apache using a different user/group? Furthermore, if a user deletes the cgi-bin folder... the fpm/fastcgi benefits are lost. Ideally, I'd like to setup PHP-FPM without the need for anything outside of the .conf file.



As far as I can tell, the php-cgi binary (which is all that the php-fpm wrapper executes) is executable by all users on the system... so why the hassle of wrapping the same executable that's going to be run by the user anyway? More specifically, how can I change this configuration to use the php-cgi binary directly, instead of going through the wrapper?



The relevant files/results related to my question are:




/etc/apache2/modules.d/20_mod_fpm.conf
---------------------------------------------------------------------------------

...

FastCgiExternalServer /var/www/localhost/cgi-bin/php-fpm -host 127.0.0.1:9000

AddHandler php-fpm .php
Action php-fpm /cgi-bin/php-fpm

DirectoryIndex index.php

...




/var/www/localhost/cgi-bin/php-fpm
---------------------------------------------------------------------------------
#!/usr/bin/php-cgi



phpinfo()

---------------------------------------------------------------------------------
...
Server API: FPM/FastCGI
...


Lovely. Running benchmarks reports that the setup is, indeed, functioning very well: with ~135 requests per second, rather than 13 requests per second using the default Apache/PHP interpreter setup. So all that's left is making the multi-user aspect seamless.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...