Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

As an example, on a Redhat/centos machines, the php-fpm is actually a binary in /usr/sbin/ directory. It intercepts call from the server (apache/nginx) to process php requests. The settings of php-fpm can be adjusted in php-fpm.conf (http://php-fpm.org/wiki/Configuration_File), which lets you fine-tune your system. php-fpm is quite advanced and gives you a lot of control to your system.

Somehow, the php-fpm file on your system seems to be more like a normal fastcgi/cgi wrapper. If you want to bypass using "your version of php-fpm" and use php-cgi directly, you can use a custom fastcgi wrapper. An example of a custom fastcgi wrapper is:

#!/bin/bash
### Set PATH ###
PHP_CGI=/usr/bin/php-cgi
PHP_FCGI_MAX_REQUESTS=1000
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI

One of the options that can be set in php-fpm.conf is to let you execute php scripts as another user. Suexec also provides this function and it can be called by Apache to pass request to the fastcgi wrapper which will handle php files. Together, suexec + fastcgi provide some of key functions of php-fpm and thus can be used as an alternative.

share|improve this answer
add comment

Using a wrapper allows you to optionally do additional configuration such as setting environment variables, selecting a php.ini file, etc.

share|improve this answer
    
Okay, so the wrapper isn't necessary after all. I'll modify my question to include the question of how to remove the wrapper from the configuration, because if I do so right now and just point FastCGIExternalServer straight to the php-cgi binary, it doesn't do the same thing as when php-cgi is executed by another application. (Something to do with the Option ExecCGI, I think?) –  Caleb Gray Jan 5 '12 at 0:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.