Syntax of Apache SetHandler directive when configuring PHP FPM
I've followed a couple of tutorials and configured Apache to use PHP FPM. However, I do not understand what part of the SetHandler
line is doing and based on some of my experiments appears to be redundant. I have the line:
SetHandler "proxy:unix:/run/php/php7.3-fpm.sock|fcgi://localhost"
This works whether the |fcgi://localhost
is present or not.
In various place, such as Plesk configuration, I've seen the portion fcgi://localhost
replaced with fcgi://127.0.0.1:9000
What is the purpose of the |fcgi://localhost
? Is it redundant and can it be removed?
Is the pipe, separating sock and fcgi in sock|fcgi
to be interpreted as an 'or', meaning if the unix socket is not present, use the tcp connection instead?
In my FPM pool configuration I've tried replacing the listen directive with a host and port, also with just a port, but I can't seem to get it to work. How would you configure PHP FPM to be available via TCP rather than a unix socket? I've no reason to want to do this at the moment, its just for learning.
Finally. Is this the correct 'stack' site to ask this question?
Edit to say I've found a small bit of documentation from Apache. The final example in the example section talks about using the |fcgi://something
in the context of forcing a reverse proxy request, but I really don't understand this.
Solution 1:
The documentation clearly states why you should include it even though it is not mandatory:
For performance reasons, you will want to define a worker representing the same
fcgi://
backend. The benefit of this form is that it allows the normal mapping of URI to filename to occur in the server, and the local filesystem result is passed to the backend. When FastCGI is configured this way, the server can calculate the most accurate PATH_INFO.