Caddy isn't working with PHP

1. Caddy version (caddy version):


2. How I run Caddy:

a. System environment:

Ubuntu 20.04 with Screen

b. Command:

screen ./caddy run

c. Service/unit/compose file:


d. My complete Caddyfile or JSON config:


localhost {
    root * /root/forum/public
    php_fastcgi unix//run/php/php8.0-fpm.sock

3. The problem I’m having:

Caddy isn’t running the index.php file in the directory. localhost/index.php returns a “file not found screen”. These are the contents of /root/forum/public:

# ls
assets  index.php  web.config

4. Error messages and/or full log output:

2022/08/21 20:15:46.570 DEBUG http.reverse_proxy.transport.fastcgi roundtrip {"request": {"remote_ip": "", "remote_port": "10282", "proto": "HTTP/2.0", "method": "GET", "host": "localhost", "uri": "index.php", "headers": {"X-Forwarded-Proto": ["https"], "Sec-Fetch-Dest": ["image"], "Accept-Encoding": ["gzip"], "Pragma": ["no-cache"], "Cf-Connecting-Ip": [""], "Sec-Fetch-Site": ["same-origin"], "Accept-Language": ["en-US,en;q=0.5"], "Cf-Ipcountry": ["T1"], "Cf-Ray": ["73e60ae98e07944d-YWG"], "X-Forwarded-Host": ["localhost"], "Sec-Fetch-Mode": ["no-cors"], "Referer": ["http://localhost/"], "Cdn-Loop": ["cloudflare"], "Cf-Visitor": ["{\"scheme\":\"https\"}"], "X-Forwarded-For": [""], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"], "Accept": ["image/webp,*/*"], "Cache-Control": ["no-cache"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "server_name": "localhost"}}, "dial": "/run/php/php8.0-fpm.sock", "env": {"REQUEST_METHOD": "GET", "HTTP_CF_CONNECTING_IP": "", "PATH_INFO": "", "SERVER_PROTOCOL": "HTTP/2.0", "DOCUMENT_ROOT": "/root/forum/public", "HTTPS": "on", "SSL_CIPHER": "TLS_AES_128_GCM_SHA256", "GATEWAY_INTERFACE": "CGI/1.1", "CONTENT_TYPE": "", "QUERY_STRING": "", "REMOTE_ADDR": "localhost", "REMOTE_HOST": "localhost", "REMOTE_USER": "", "HTTP_CACHE_CONTROL": "no-cache", "HTTP_CDN_LOOP": "cloudflare", "REMOTE_IDENT": "", "HTTP_SEC_FETCH_MODE": "no-cors", "HTTP_REFERER": "http://localhost/", "HTTP_CF_VISITOR": "{\"scheme\":\"https\"}", "SERVER_NAME": "localhost", "SCRIPT_NAME": "/index.php", "SERVER_PORT": "443", "HTTP_CF_RAY": "73e60ae98e07944d-YWG", "HTTP_X_FORWARDED_HOST": "localhost", "HTTP_PRAGMA": "no-cache", "HTTP_X_FORWARDED_PROTO": "https", "CONTENT_LENGTH": "", "REQUEST_SCHEME": "https", "DOCUMENT_URI": "index.php", "SCRIPT_FILENAME": "/root/forum/public/index.php", "HTTP_ACCEPT_ENCODING": "gzip", "HTTP_SEC_FETCH_SITE": "same-origin", "HTTP_SEC_FETCH_DEST": "image", "AUTH_TYPE": "", "HTTP_HOST": "localhost", "SSL_PROTOCOL": "TLSv1.3", "HTTP_X_FORWARDED_FOR": "", "HTTP_ACCEPT": "image/webp,*/*", "REMOTE_PORT": "10282", "REQUEST_URI": "/favicon.ico", "HTTP_ACCEPT_LANGUAGE": "en-US,en;q=0.5", "HTTP_CF_IPCOUNTRY": "T1", "HTTP_USER_AGENT": "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0", "SERVER_SOFTWARE": "Caddy/v2.5.2"}}

5. What I already tried:

Changing folder, trying a different PHP sock.

6. Links to relevant resources:

Sounds like a file permission issue.

Don’t put your files in /root, because then only the root user will be able to read files.

PHP doesn’t run as root, it runs as www-data typically (depends on the linux distro). So it won’t be able to read files owned by root.

I strongly recommend moving your files to either /srv or /var/www.

Also, run Caddy as a service, don’t run it directly.


Worked like a charm, thank you!

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