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 have the following in my Apache conf to get PHP-FPM working:

FastCgiExternalServer /srv/www/fast-cgi-fake-handler -host 127.0.0.1:9000
AddHandler php-fastcgi .php
AddType text/html .php
Action php-fastcgi /var/www/cgi-bin
Alias /var/www/cgi-bin /srv/www/fast-cgi-fake-handler
DirectoryIndex index.php

This works fine except that SCRIPT_NAME is always /var/www/cgi-bin and some scripts use SCRIPT_NAME to work out the location of the current script (vBulletin).

Google has plenty of solutions for Nginx but not a word for Apache.

share|improve this question
add comment

4 Answers 4

If you use RewriteRule in place of "Action" method, it will work out just fine

Given below is an example I used to in Apache to connect to FCGI::Daemon external fastcgi daemon process. This daemon can be considered as a perl's version of php-fpm.

<VirtualHost 127.0.0.1:80>
    ServerAdmin info@example.com
    DocumentRoot "/var/www/example"
    ServerName www.example.com

    <IfModule mod_fastcgi.c>
    FastCGIExternalServer /var/www/fcgi-daemon/perl.fcgi -socket /var/run/fcgi-daemon.sock
    ScriptAlias /perl.fcgi /var/www/fcgi-daemon/perl.fcgi
    </IfModule>
</VirtualHost>

<Directory /var/www/example/cgi-bin>
    Options ExecCGI
    RewriteRule ^(.*)$ /perl.fcgi [L]
</Directory>

Note: "/var/www/fcgi-daemon/" has to exist! as blank directory. Actual the method you used for php does not work out of box for perl daemon. SCRIPT_FILENAME was always /var/www/fcgi-daemon/perl.fcgi which never existed, leading to error. Using RewriteRule kept all the required environment variables in place and passed them along to perl fastcgi daemon.

share|improve this answer
add comment

I found that when setting FastCgiExternalServer to a directory that exists (probably works for a file too) such as /srv/www then all the PHP variables were set correctly. However, all non-PHP content would serve as either text/html or text/plain which isn't very good. Also DirectoryIndex stopped having an effect which reminds me of this question over at StackOverflow but I couldn't get anywhere with his solution of juggling absolute and relative paths.

The only relevant Google result for PHP-FPM, Apache and SCRIPT_NAME is a comment by someone called Dimas who says that this method fixed it for him, but I had no such luck.

I've resorted to setting auto_prepend_file in my php.ini to a file containing the following:

<?php
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
unset($_SERVER['PATH_TRANSLATED']);
$_SERVER['SCRIPT_NAME'] = $_SERVER['PATH_INFO'];
unset($_SERVER['PATH_INFO']);

Not the best solution but at least I don't have to manually edit vBulletin, Wordpress, etc.

share|improve this answer
add comment

You can fix this by ensuring that cgi.fix-pathinfo in your php.ini is set to 1. That causes PHP to populate the $_SERVER array as you would expect when executing PHP as CGI/FastCGI on Apache.

share|improve this answer
add comment

http://serverfault.com/a/423965/118969 by ColtonCat above, is the best answer. I've tried it using nginx (ssl-reverse-proxy) -> apache -> php53-fpm.

if using nginx (ssl-reverse-proxy) -> apache + mod_php, you can use cgi.fix_pathinfo=0

share|improve this answer
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.