caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
55.71k stars 3.92k forks source link

v2: PHP-FPM using socket but "missing port in address?" #3034

Closed ghost closed 4 years ago

ghost commented 4 years ago

VERSION:

v2.0.0-beta.13 h1:QL0JAepFvLVtOatABqniuDRQ4HmtvWuuSWZW24qVVtk=

CONFIG:

domain.com, www.domain.com {
    root * /home/caddy
    encode gzip
    php_fastcgi / unix//var/run/php/php7.3-fpm.sock php 
    #php_fastcgi / 127.0.0.1:9000 php   
    file_server
}

PROBLEM:

php_fastcgi / unix//var/run/php/php7.3-fpm.sock php = error: missing port in address
php_fastcgi / 127.0.0.1:9000 php = error: dialing backend: dial tcp 127.0.0.1:9000: connect: connection refused

I can't get PHP-FPM to work. I get errors either way I try and configure it. Port 9000 is open in UFW so I dont know what is causing the connection refused on that. The first error cause a 500 and the second causes a 502.

I'd like to use the socket not the port since its on the same machine.

Ive read pretty much every post about PHP-FPM and Caddy2 and none of it is working for me.

mholt commented 4 years ago

Whatever php is, it needs a port -- the server doesn't know what port to dial if it only has a hostname. You need something like php:5000 or whatever.

Edit: Huh, only half my reply got in... weird.

As for this:

Port 9000 is open in UFW so I dont know what is causing the connection refused on that.

I don't know what's causing the connection to be refused either, you'll have to debug that on your system. This should be obvious, but make sure php-fpm is listening at that address.

ghost commented 4 years ago

so php_fastcgi / unix//var/run/php/php7.3-fpm.sock php should be php_fastcgi / unix//var/run/php/php7.3-fpm.sock php:9000 (or whatever) ?

whitestrake commented 4 years ago

Why is php on the end there? Are you emulating the old v1 fastcgi PHP preset?

I note that there is no such preset in v2, the syntax only calls for two parameters - a matcher and the upstream server: https://caddyserver.com/docs/caddyfile/directives/php_fastcgi

Therefore, php here is being interpreted as a second upstream. If you have a second upstream located at php:9000, then yes, it should be php:9000. If you're just carrying over the preset from v1, drop it entirely; just use php_fastcgi / unix//var/run/php/php7.3-fpm.sock.

whitestrake commented 4 years ago

P.S. re: connection refused - it could occur for an open port that no program is currently listening on, the operating system is the one issuing a refusal in this case. If you've got PHP-FPM listening on the socket, did you disable the port 9000 listener maybe? Just something to double check, although hopefully unnecessary if you get the socket working.

ghost commented 4 years ago

Why is php on the end there? Are you emulating the old v1 fastcgi PHP preset?

I note that there is no such preset in v2, the syntax only calls for two parameters - a matcher and the upstream server: https://caddyserver.com/docs/caddyfile/directives/php_fastcgi

Therefore, php here is being interpreted as a second upstream. If you have a second upstream located at php:9000, then yes, it should be php:9000. If you're just carrying over the preset from v1, drop it entirely; just use php_fastcgi / unix//var/run/php/php7.3-fpm.sock.

im getting conflicting info about how to get php to work in caddy. i want to use caddy2 but i cant tell whats caddy1 and whats caddy2.

whitestrake commented 4 years ago

Huge amounts of threads on the community forums relate to v1 because v2 is relatively very new. Assume that any thread that doesn't explicitly mention v2 is not applicable at all.

Here's the official home of Caddy v2 documentation: https://caddyserver.com/docs/

I have also linked the php_fastcgi documentation in the comment you quoted.

Try that one with just the unix socket and no php on the end and let us know if it works. Hopefully you should be up and running with just that.

mholt commented 4 years ago

@dogpatchmedia

im getting conflicting info about how to get php to work in caddy. i want to use caddy2 but i cant tell whats caddy1 and whats caddy2 in the documentation

By default, the docs are for Caddy 2 now. Just look at the big banners at the top of each page:

Screen Shot 2020-02-10 at 10 55 06 PM Screen Shot 2020-02-10 at 10 55 19 PM

I don't think that's very difficult... also v1 docs have /v1/ in the URL.

since the actual docs suck pretty bad are are just the most basic of basic.

You can help improve them instead of complaining that they "suck pretty bad", you know. The docs are open source: https://github.com/caddyserver/website

Thank you, @whitestrake, for helping!