Help with PHP-FPM

1. Output of caddy version:

v2.5.2 h1:eCJdLyEyAGzuQTa5Mh3gETnYWDClo1LjtQm2q9RNZrs=

2. How I run Caddy:

a. System environment:

Debian 11 on WSL with systemd-genie installed (so, systemd works)

b. Command:

sudo systemctl start caddy

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddy config:

:63342 {
        root * /srv/php
        encode gzip
        php_fastcgi unix//run/php/php8.1-fpm-testsite.sock
        file_server

        log {
                output file /var/log/testsite.log
        }
}

3. The problem I’m having:

I have a very simple

<?php

   phpinfo();

Script located at /srv/php/test.php. I’m trying to view its output (and thereby confirm that the web server is functioning correctly) via my PhpStorm editor’s preview functionality. It keeps attempting to use port 63342, which is why I modified my Caddyfile to listen to that port specifically.

I’m used to using NGINX in a multiple virtual host setup, so I created a testsite user and a separate PHP-FPM for it (located at /etc/php/8.1/fpm/pool.d/testsite.conf):

[testsite]
user=testsite
group=testsite
listen=/var/run/php/php8.1-fpm-testsite.sock
listen.owner=www-data
listen.group=www-data
php_admin_value[disable_functions]=exec,passthru,shell_exec,system
php_admin_flag[allow_url_open]=off
pm=dynamic
pm.max_children=5
pm.start_servers=2
pm.min_spare_servers=1
pm.max_spare_servers=3
chdir=/

The /srv/php/test.php file is owned by the testsite user

4. Error messages and/or full log output:

journalcltl -u caddy --no-pager | less +G output:

ws/System32
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: INSIDE_GENIE=yes
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: WSL_DISTRO_NAME=Debian
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: WSL_INTEROP=/run/WSL/763_interop
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: WSLENV=
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: DISPLAY=:0
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: WAYLAND_DISPLAY=wayland-0
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: PULSE_SERVER=/mnt/wslg/PulseServer
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: NOTIFY_SOCKET=/run/systemd/notify
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: HOME=/var/lib/caddy
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: LOGNAME=caddy
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: USER=caddy
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: INVOCATION_ID=6c3445e0728d444b8ab686fc4e7864ef
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: JOURNAL_STREAM=7:23027
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: {"level":"info","ts":1661736371.5275252,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":""}
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: {"level":"info","ts":1661736371.5290816,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["//[::1]:2019","//127.0.0.1:2019","//localhost:2019"]}
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: {"level":"info","ts":1661736371.5293207,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000156bd0"}
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: {"level":"info","ts":1661736371.5295382,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:/var/lib/caddy/.local/share/caddy"}
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: {"level":"info","ts":1661736371.5295572,"msg":"autosaved config (load with --resume flag)","file":"/var/lib/caddy/.config/caddy/autosave.json"}
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: {"level":"info","ts":1661736371.529564,"logger":"tls","msg":"finished cleaning storage units"}
Aug 28 21:26:11 KEVIN-DESKTOP-wsl caddy[3612]: {"level":"info","ts":1661736371.5296655,"msg":"serving initial configuration"}
Aug 28 21:26:11 KEVIN-DESKTOP-wsl systemd[1]: Started Caddy.

No errors outside of a 502 Bad Gateway. Nothing logged at /var/log/testsite.log

5. What I already tried:

Double-checked my FPM config setup with what works with my NGINX setups. Added the log directive to my Caddyfile in the hopes of getting some hint of what’s not working. Moved the test file out of my home directory. Changed the port in the Caddyfile to what PhpStorm is trying to use.

6. Links to relevant resources:

Try adding the debug global option at the top of your Caddyfile:

{
	debug
}

It should show you more in the logs.

But if it doesn’t, then it’s simply because Caddy is never being reached. It might be a WSL networking issue, still.

1 Like

Unfortunately, I wasn’t able to get it to work with WSL2. Like you say, it does weird things with networking. Whomp whomp. Hopefully WSL3 or 4 will be a bit more sane.

That said, I was able to get it working with the new Kubuntu virtual machine I made for development!

Once again, thank you for your patience and help!

1 Like

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