The following is PHP-FPM (PHP 5.5)
php-cgi.exe -b 127.0.0.1:9000
The following is mod_proxy_fcgi (Apache 2.4)
The first way
<Files ~ "\.(php|phtml)$">
SetHandler "proxy:fcgi://127.0.0.1:9000/"
</Files>
The second way
<LocationMatch ^(.*\.(php|phtml))$>
ProxyPass fcgi://127.0.0.1:9000/$1
</LocationMatch>
The third way
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^([^\.]+\.(php|phtml))$ fcgi://127.0.0.1:9000/$1 [P,L]
</IfModule>
The above three ways will get an error "No input file specified." Anybody know why? How should I do to solve this problem?
Inexplicably, simply changing the trailing
/
to a#
seems to fix the problem:In trying to understand this I set Apache to
LogLevel debug
(timestamp/module/process details removed for brevity):Using
/
gives:Using
#
gives:The crucial difference appears to be in the last line, where the second (working) method doesn't appear to log anything as the value passed to the PHP process.
I'm at a loss to explain this and can't find mention of it anywhere. (Perhaps a braver soul than I would be willing to delve into the Apache and/or PHP source to investigate.)
Note that I haven't tested this beyond running
phpinfo()
so wouldn't recommend it for a production server.Edit
This works for PHP 7.0, but with PHP 5.6 I still get the 'No input file specified' error.
Edit 2
And working with Apache 2.4.25, but not the recently released 2.4.26!
This seems to be an incompatibility minefield that is explicitly mentioned in the CHANGES_2.4.26 file:
The documentation has been updated to reflect this:
I think this is a bug in mod_proxy_fcgi, connected to an issue resolved in Apache 2.4.12 onwards:
mod_proxy_fcgi: Remove proxy:balancer:// prefix from SCRIPT_FILENAME passed to fastcgi backends. [Eric Covener]
Here is a link
Unfortunatelly it was not good enough as Apache is sending the SCRIPT_FILENAME with a starting slash, similar to \c:\fileName.php, which is not resolved as a local file name and is never executed. You may verify this using a network sniffer(Wireshark) listening on your FastCGI port.
I will be more than happy to see this issue resolved officially since I am not confident in recompiling Apache by myself and so I am using distributions from apachelounge.
Maybe you didn't get me right.
Before the fix it was: proxy:balancer://\c:\fileName.php
After the fix it is: \c:\fileName.php
Which are both invalid file names in Windows, while thinking Linux there is no drive letter there so it becomes \fileName.php which is valid. The fix would be to remove the starting slash and recompile.
I was getting this error when following the steps indicated here to run PHP under Apache on Windows via FastCGI:
https://www.orbitale.io/2017/11/11/apache-and-php-fpm-in-windows.html
After setting up php-cgi.exe as a service on port 9000 (using NSSM) and setting httpd.conf to handle php files as such:
I was getting this same error when navigating to localhost (which contained an index.php with a simple
<?php phpinfo(); ?>
.I was getting worried until I tried editing my php.ini where I defined the doc_root directive:
Having done that and having restarted my Apache service, voilà I got the php info page! I'm using PHP 7.3.5 NTS x64 with Apache 2.4 x64.