Settings Caddy for php7.1-fpm

(Dmitry Smirnov) #1

Hello everyone! I need a help.

I get 502 Bad Gateway. Prompt where to dig?
Thanks for all.

My Caddyfile:

In workspace one php file:

Him content is:

But the same settings work in MacOS.

(Matthew Fay) #2

Is PHP-FPM enabled and listening on port 9000?

(Dmitry Smirnov) #3

Problem is successfully solved!
In file /etc/php/7.1/fpm/pool.d/www.conf it was not spelled out listen =, was spelled only listen = /run/php/php7.1-fpm.sock.

I just tried using the first option to connect.

(Dmitry Smirnov) #4

Thank you for paying attention to my topic. Below I posted the answer. :smile:
As far as I remember, in earlier versions it was written listen =

(Matthew Fay) #5

Optionally, you could leave php7.1 in a default state and configure Caddy to connect to the socket:

fastcgi / unix:/run/php/php7.1-fpm.sock php

(Dmitry Smirnov) #6

While I do not understand why, but this fastcgi / unix:/run/php/php7.1-fpm.sock php doesn’t work.
But I would like to use socket.

(Matthew Fay) #7

Just double-checked the syntax, that’s the correct usage.

Did you change /etc/php/7.1/fpm/pool.d/www.conf back to listen = /run/php/php7.1-fpm.sock?

(Dmitry Smirnov) #8

But I get 502 status.

(Matthew Fay) #9

Comment out listen = in pool.d - I’m not sure, but I suspect it might be overwriting the previous value.

(Dmitry Smirnov) #10

Didn’t work. I saw settings when it was two comments and it worked.

(Matthew Fay) #11

Ahh, ok.

What user is Caddy running under? The socket permissions are set only to be readable by www-data.

(Dmitry Smirnov) #12

(Matthew Fay) #13

Hmm, not quite what I meant. See listen.owner and in pool.d - in combination with the default listen.mode of 0660, a process can’t read from /run/php/php7.1-fpm.sock unless its user or group is www-data.

That means Caddy itself - not PHP - needs to be run as www-data (or root), or it won’t be able to read from the socket (and it will timeout, generating 502s).

(Dmitry Smirnov) #14

I see that comment ;listen.mode = 0660, may be it is problem…
Or change settings on my home user…
I also tried to run the Caddy from different users.

(Matthew Fay) #15

Did you try www-data, specifically?

Ahh, I see you did. Hmm. And your PHP page didn’t work for either www-data or root?

(Dmitry Smirnov) #16

Yes, it is dosn’t work. But usually I run just a home user, whitout sudo.

(Matthew Fay) #17

Strange, especially if it didn’t work as root, which heavily implies PHP-FPM wasn’t listening on the socket at all.

I’m not sure what else to try, I’m afraid.

(Dmitry Smirnov) #18

Problem solved, the socket works!
I have deleted comment out listen =
Switched to user www-data using sudo -su www-data, then run caddy command caddy.
You were right!

Thank you very much, Matthew! Strong health, man!

(system) #19

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.