Caddy refusing connection to basic PHP script configuration

1. The problem I’m having:

Caddy webserver is refusing connections to my website, which is just a basic PHP script echoing phpinfo()

2. Error messages and/or full log output:

When navigating to my domain configured in Caddyfile, I see this request error:

ERROR   http.log.error  dialing backend: dial tcp 127.0.0.1:9000: connect: connection refused 
 {"request": {"remote_ip": "127.0.0.1", "remote_port": "58885", "client_ip": "127.0.0.1", "proto": "HTTP/2.0", "method": "GET", "host": "inv.localhost", "uri": "/", "headers": {"Sec-Fetch-Mode": ["navigate"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"], "Accept-Encoding": ["gzip, deflate, br"], "Upgrade-Insecure-Requests": ["1"], "Sec-Fetch-Dest": ["document"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-User": ["?1"], "Te": ["trailers"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0"], "Accept-Language": ["en-US,en;q=0.5"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "server_name": "inv.localhost"}}, "duration": 0.00638229, "status": 502, "err_id": "4sxjdd84f", "err_trace": "reverseproxy.statusError (reverseproxy.go:1265)"}

3. Caddy version:

v2.7.5

4. How I installed and ran Caddy:

I installed via homebrew… brew install caddy

I run in the same directory as my Caddyfile: caddy run

a. System environment:

This is running on Macos 12.6 Monterey

d. My complete Caddy config:

inv.localhost {
      root * /Users/nateschreiner/projects/test/
      php_fastcgi 127.0.0.1:9000
      file_server
 }

Ok, so in doing some digging, I had verified I didn’t have any VPN connections that may cause network disruptions, or a firewall that was causing the connection to be blocked.

I then wanted to double check php-fpm was running. I had assumed it was this whole time as in my many years of using MacOS, php-fpm was never something I had to start / stop / restart manually.

I checked my php-fpm config file in /usr/local/etc/php/8.2/php-fpm.d/www.conf and saw 127.0.0.1:9000 was the listening address for the process.

doing a sudo lsof -i -P | grep LISTEN | grep 9000 didn’t show any processes so I assumed php-fpm somehow got stopped.

Sure enough running from php-fpm from /usr/local/opt/php/sbin and then checking my domain configured in my Caddyfile, finally worked.

Not sure what would cause php-fpm to stop on MacOS, but I’ll consider this problem solved.

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