1. The problem I’m having:
Hello, I need help setting up Caddy with a PHP website. I made several attempts, but each time, I encounter either an error 403 or a blank page. In Caddy’s configuration logs, I don’t find any errors.
2. Error messages and/or full log output:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
3. Caddy version:
Caddy version : v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=
4. How I installed and ran Caddy:
a. System environment:
OS : Ubuntu 22.04
Docker : NO
Website : /home/ubuntu/website/
CaddyFile : /etc/caddy/Caddyfile/
PHP : 8.1.2
b. Command:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
c. Service/unit/compose file:
/etc/php/8.1/fpm/pool.d/www.conf
; Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[www]
; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or /usr) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = caddy
group = caddy
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /run/php/php8.1-fpm.sock
; Set listen(2) backlog.
; Default Value: 511 (-1 on FreeBSD and OpenBSD)
;listen.backlog = 511
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions. The owner
; and group can be specified either by name or by their numeric IDs.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = caddy
listen.group = caddy
;listen.mode = 0660
d. My complete Caddy config:
:80 {
root * /home/ubuntu/website
encode gzip
file_server
php_fastcgi unix//run/php/php8.1-fpm.sock
log {
output file /var/log/caddy/website.com.access.log
}
}
When I start the configuration with PHP, everything works, but when I change the path to the “index.php” file of the website, something is wrong.
Precision: modification of website permissions using chmod 777.
Here is the configuration where it worked when I was doing the PHP test.
nano /usr/share/caddy/info.php
<?php
phpinfo();
?>
Caddyfile
:80 {
root * /usr/share/caddy/
encode gzip zstd
php_fastcgi unix//run/php/php8.1-fpm.sock
}