5

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.

Dom
  • 458
  • 1
  • 5
  • 15
  • 2
    Yes, this is the right place. See also [my question](/questions/1041582) about `SetHandler proxy:unix:...` I haven't found a complete explanation of it anywhere yet. – Andrew Schulman Nov 29 '20 at 13:10
  • @AndrewSchulman I've just updated my question to point towards some Apache documentation, which I've found, but which I don't understand. – Dom Nov 29 '20 at 15:36
  • Can you share the goal you are trying to achieve and the rest of your relevant configuration? ``localhost`` is the same as ``127.0.0.1``. The example specified a custom port (``9000``) instead of the default port. I do not know of the top of my head which port FCGI uses by default. – Tommiie Dec 01 '20 at 12:18
  • 1
    @Tommiie My goal is to understand the inclusion of `|fcgi://localhost` in the samples I've found and in the Apache docs, when the configuration works without it. What does it mean, what does it do, when and why would you choose to use it? – Dom Dec 01 '20 at 15:02

1 Answers1

4

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.

Tommiie
  • 5,627
  • 2
  • 12
  • 46