Multi sites, php not resolve

1. My Caddy version (caddy -version):

1.0.1

2. How I run Caddy:

Please provide all of the relevant information and DO NOT REDACT anything except passwords/keys. Thank you!

a. System environment:

OS, relevant versions, systemd? docker? etc.

Oracle Linux 7.7, systemd , no docker

b. Command:

paste command here

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile:

http:// {
    root /var/www/html/
    gzip
    fastcgi / /run/php-fpm/www.sock php {
         ext .php
         split .php
         index index.php
    }
}


ooxx.net {
    root /var/www/ooxx.net/
    gzip
    tls xxoo@ooxx.com
    errors /var/log/caddy/errox.log
    fastcgi / /run/php-fpm/www.sock php {
         ext .php
         split .php
         index index.php
    }
}

3. The problem I’m having:

Please describe the issue thoroughly enough so that anyone can reproduce the exact behavior you’re seeing. Be as specific as possible.

my Caddyfile shown above, but php only work at the default site, the site ooxx.net not work. The log files reads.

How to make php work for the site ooxx.net? Further more ,is there any way to make settings like php and gzip to be public for all sites?

4. Error messages and/or full log output:

Please DO NOT REDACT any information except passwords/keys.

[ERROR 0 /index.php] PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0Unable to open primary script: /var/www/ooxx.net/index.php (Permission denied)

5. What I already tried:

the user, and the listener of php-fpm service has been set to www-data, the same as the Caddy service.
The owner of the directory /var/www/html and /var/www/ooxx.net have been set to www-data.

I use to chmod the php files in the dir ooxx.net to 0777. But the permission still denied.

6. Links to relevant resources:

Hi @sharoue, welcome to the Caddy community.

What’s your unit file?

Out of curiosity, have you tried this with any other webservers?

sorry, i cannot quite follow the meaning of “unit file”… @Whitestrake

i havent tried other webservers at this vps before, since to me oracle linux is a little bit… awesome. For apache the php support is configured auto at the debian-like linux and always ok, so i think there is something wrong with my own settings.

The unit file is what systemd uses to configure the process running as a service.

You should be able to use systemctl cat [service], where [service] is the name of the Caddy service on your system, to display the unit file.

Do you also run php-fpm via systemd? Might help to list that unit file as well.

@Whitestrake
at the default site /var/www/html/, php resolving works

unit file like this
cat /etc/systemd/system/caddy.service | grep -v ;

[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Restart=on-abnormal

StartLimitIntervalSec=14400
StartLimitBurst=10

User=www-data
Group=www-data

Environment=CADDYPATH=/etc/ssl/caddy

ExecStart=/usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp
ExecReload=/bin/kill -USR1 $MAINPID

KillMode=mixed
KillSignal=SIGQUIT
TimeoutStopSec=5s

LimitNOFILE=1048576
LimitNPROC=512

PrivateTmp=true
PrivateDevices=false
ProtectHome=true
ProtectSystem=full
ReadWritePaths=/etc/ssl/caddy
ReadWriteDirectories=/etc/ssl/caddy


[Install]
WantedBy=multi-user.target

and the unit file of php-fpm like this

# /usr/lib/systemd/system/php-fpm.service
# It's not recommended to modify this file in-place, because it
# will be overwritten during upgrades.  If you want to customize,
# the best way is to use the "systemctl edit" command.

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=notify
ExecStart=/usr/sbin/php-fpm --nodaemonize
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
RuntimeDirectory=php-fpm
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target

But not in /var/www/ooxx.net/?

Can you list the output of: ls -al /var/www

like this @Whitestrake

$ ls -al /var/www
total 8
drwxr-xr-x.  5 root     root   52 Oct 16 12:05 .
drwxr-xr-x. 21 root     root 4096 Oct 15 07:03 ..
drwxr-xr-x.  2 root     root    6 Aug 25 19:42 cgi-bin
drwxr-xr-x.  2 www-data root   37 Oct 15 07:57 html
drwxrwxr-x.  6 www-data opc  4096 Oct 18 12:46 ooxx.net

i doubt that the issue happens with ‘/’,
no matter i set the php for the default site or not,
the php of site ooxx.net just don’t work.

i used to make setting like

fastcgi ooxx.net/ /run/php-fpm/www.sock php {

however it did not work either.

As far as I know,

[ERROR 0 /index.php] PHP message: PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0Unable to open primary script: /var/www/ooxx.net/index.php (Permission denied)

The fact that we have an error here from PHP means that Caddy is properly configured and is passing requests off to PHP-FPM and getting responses back. So there’s nothing here to fix in the Caddyfile, it’s already working.

The issue is that PHP doesn’t seem to be configured with the right permissions to access the files. Something is denying permissions. I don’t see systemd doing anything along those lines, so possibly it’s an issue with the PHP-FPM configuration, but I’m not sure.

I don’t know why…I chmod -R the ooxx.net to 0777 and it is still not OK.
Finally I deleted the directory ooxx.net and rmdir again… it works。。。

1 Like

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