PHP FPM 7.2 doesn't work with Caddy 2

1. Caddy version:


2. How I run Caddy:

Installed this Marketplace package of Ubuntu + Caddy at my DigitalOcean VPS

a. System environment:

Ubuntu 18.04.4

b. Command:

caddy run

c. Service/unit/compose file:

d. My complete Caddyfile or JSON config:

	email	*****@*****.***
} {
	root * /var/www/
	encode zstd gzip
	php_fastcgi / unix//run/php/php7.2-fpm.sock
} {

3. The problem I’m having:

PHP-FPM is successfully running on socket (I used netstat -pl | grep php to check that), Caddy is running, Caddyfile is working (my website is running), but looks like PHP-FPM doesn’t get anything for processing. And every .php file just outputs its raw content if accessed directly in the browser.

I can’t find any Caddy log file, there isn’t any caddy-related log file in /var/log. I even can’t understand the core of this problem.

You can see PHP not working on my website here (clock isn’t running) and here (contact form doesn’t send enything). (I also have other client websites that have a bit more serious php scripts not working completely.)

4. Error messages and/or full log output:

No error messages, HTML works fine, but PHP doesn’t work at all while still running.

5. What I already tried:

Tried this:

sudo reboot
sudo service caddy restart
sudo service php7.2-fpm restart

Also tried to check files permissions, every .php file has 644. Nothing works for me.

Remove the first /, that’s making it match only requests to / and not /somepath. In Caddy v2, path matchers are exact match, not prefix match. Removing / will make it assume * instead, meaning “any path”.

php_fastcgi unix//run/php/php7.2-fpm.sock

You can read up on matchers here:

You should remove the / between the domain and {uri}, because {uri} already contains the /

You need to enable access logs:

1 Like

Thank you so much! It finally worked!
Also thank you for noticing that nasty /.

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