I get 502 status. Caddy + php7.2-fpm.sock

(Dmitry Smirnov) #1

Hello everyone! I need your a help.

I get 502 status. Caddy + php7.2-fpm.sock

It works:
localhost:8087 {
root /Users/kryptoncode/Projects/hastore/public
fastcgi / php

Dont works:
localhost:8087 {
root /Users/kryptoncode/Projects/hastore/public
fastcgi / unix:/run/php/php7.2-fpm.sock php

Excerpt from:
Of course activated need comments in different cases.

I also tried to run from user _www command su _www -c caddy, but it was not successful, I get similarly 502 status.

OS: MacOS High Sierra 10.13.1
I noticed that there is no such problem in Ubuntu.
Maybe I have the wrong path to the socket…
Does anyone have any idea about this problem?

Thanks to all who responded!

(Matthew Fay) #2

Hi @krypton-code,

Just to confirm, you have configured the listen entries in www.conf like so (with the port and the /tmp socket lines commented out):

;listen =
listen = /run/php/php7.2-fpm.sock
;listen = /tmp/php-fpm.sock

And your fastcgi directive in your Caddyfile is as follows:

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

I’d recommend trying to run Caddy as root next - if it works, you know the socket is active, otherwise your www.conf may be misconfigured.

(Dmitry Smirnov) #3

Hi @Whitestrake,

Now my www.conf looks like this:
listen = /run/php/php7.2-fpm.sock

And Caddyfile:
localhost:8000 {
root /Users/kryptoncode/Projects/hastore/public
fastcgi / unix:/run/php/php7.2-fpm.sock php
rewrite {
to {path} {path}/ /index.php?{query}

Caddy to run as root: sudo caddy
Get 502

I also tried to run it command:
su root -c caddy
and get 502

I have the correct path to the socket in my www.conf?

(Matthew Fay) #4

Yes - whatever is written in www.conf will be used, so if you copy the path out of that and into your Caddyfile, it will be correct.

Did you restart PHP-FPM after changing www.conf?

(Dmitry Smirnov) #5

Did you restart PHP-FPM after changing www.conf?

Yes, of course, I do this always, after editing.
Command: brew services restart php72

(Matthew Fay) #6

It all looks well configured to me. The next step might be to try removing Caddy from the setup to determine if it’s the cause of the problem. Try configuring nginx instead and see if it works with the socket.

(Dmitry Smirnov) #7

Setup nginx, the problem is the same, get 502.

In MacOS php-fpm.sock located here, but you speak that place is true /run/php/php7.2-fpm.sock.
Where is a true?) I dont know)

This settings work with Nginx:

(Dmitry Smirnov) #8

I found that with this setting listen = /run/php/php7.2-fpm.sock in file www.conf php does not start at all, that is the config is not correct.

PHP work only listen = /tmp/php-fpm.sock

After reading all the comments in the config file /usr/local/etc/php/7.1/php-fpm.d/www.conf I realized what the problem is:
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = user under which to run php
group = group of this user under which to run php

It is also important that Caddy was launched under the same user, otherwise will be nothing work.

p.s.: what in my posts different version of php - it doesn’t matter, I just thought that the 7.2 version of the problem, it turned out that it is not.

(Mikorist) #9

I had a similar problem.
With php-7.0-fpm.
This works very well.