7

With Apache 2.4.26 using php-fpm 7.1.6, $_SERVER['SCRIPT_FILENAME'] (and $_SERVER['PHP_SELF']) is incorrect on a folder:

Apache 2.4.26:

/index.php

Apache 2.4.25:

/myfolder/index.php

What is wrong?

neoteknic
  • 1,930
  • 16
  • 32

2 Answers2

11

I fixed it in apache config with this new config directive :

ProxyFCGIBackendType GENERIC

In global configuration before the SetHandler directive. Default is FPM, but it's not correct with some php-fpm configuration (SetHandler and socket).

With this bug all $_SERVER['SCRIPT_FILENAME'] and $_SERVER['PHP_SELF'] Apache vars ($_SERVER) (injected from php-fpm) are wrong, they don't have the path!

ProxyFCGIBackendType is default to FPM but it's wrong for many configuration. Apache httpd should add GENERIC as default to don't break websites.

See: https://httpd.apache.org/docs/2.4/en/mod/mod_proxy_fcgi.html#proxyfcgibackendtype

leek
  • 11,803
  • 8
  • 45
  • 61
neoteknic
  • 1,930
  • 16
  • 32
  • FWIW they are aware of it and working on it for next version. – Daniel Ferradal Jun 21 '17 at 18:04
  • 2
    Worked for me as well. Added it at the top of the etc/sites-available file – lprent Jun 28 '17 at 15:08
  • Do you know how i fix/change this inside a puphpet/vagrant setup? – Michael Jul 05 '17 at 14:39
  • 1
    @Michael: Add it to your `.htaccess` or to PuPHPet's Virtual Host-Level Custom Directives. – leek Jul 06 '17 at 20:17
  • @leek Thank you, adding it to the htaccess works. But i dont understand what/where i have to change it in "PuPHPet's Virtual Host-Level Custom Directives". Do you mean the config.yaml or one of the files in the puphpet folder? – Michael Jul 07 '17 at 09:21
  • Ok i found it. Its puphpet/puppet/modules/apache/templates/httpd.conf.erb – Michael Jul 07 '17 at 14:09
1

(This would be better as a comment, but I'm under the minimum rep.)

Like neoteknic points out in their answer, using the GENERIC backend type will revert you to 2.4.25 behavior while we get this bug worked out.

Note, however, that the 2.4.25 behavior breaks some other people too and is not a panacea. If you're in a bind, the new ProxyFCGISetEnvIf directive can give you direct control over FCGI envvars, and it accepts httpd expression syntax for some pretty complex manipulations, if you need them. This only helps if you understand what those envvars are supposed to be, but it's another option.