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.

https://drive.google.com/open?id=1LKb5NbHQOAUpUBvoMcgPRd9ujIBb-2xu

My Caddyfile:

https://drive.google.com/open?id=14ZJXncJrT0gG1OZi4hPocez2DYK8FgOo

In workspace one php file:

https://drive.google.com/open?id=1Cd_gVjzY5QiIMG6W1LHxDkDC7G3oQdqY

Him content is:

https://drive.google.com/open?id=1zHdPJrh95h4Htoo-UAv7eJ5P9Gv1cqhO

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 = 127.0.0.1:9000, 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 = 127.0.0.1:9000.


(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

https://drive.google.com/open?id=1NL5lNEyFfCephG5whnENDfkO4JrgM8Zb
https://drive.google.com/open?id=1x5AZRIahhGhdgRz48w6TkVa5aQ1L8QXT

But I get 502 status.


(Matthew Fay) #9

Comment out listen = 127.0.0.1:9000 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

https://drive.google.com/open?id=1TTnWeh1qYdmgYYt6Q9i_GYUSf1E5ErtK
https://drive.google.com/open?id=1wJ9SBh2B_mhRo4Il9QgzVZyhNItQM6_r


(Matthew Fay) #13

Hmm, not quite what I meant. See listen.owner and listen.group 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

https://drive.google.com/open?id=1Dk6EZkfkTI6zjr7TK_kI2eLjQ1sAvH9V
https://drive.google.com/open?id=1EZyz_R5pb0mPVh3cl2BlkIMEYh4JjLPq

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

Cheers!
Problem solved, the socket works!
I have deleted comment out listen = 127.0.0.1:9000.
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.