Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following in my Apache conf to get PHP-FPM working:

FastCgiExternalServer /srv/www/fast-cgi-fake-handler -host
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

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.

    DocumentRoot "/var/www/example"

    <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

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

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

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:


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

share|improve this answer

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 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

Your Answer


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.