PHP: "No input file specified." - but, I did?

1. Output of caddy version:

 caddy version
v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=

2. How I run Caddy:

OpenWRT doesn’t use SystemD and has no Caddy package per-se, so I run it via /etc/rc.local and use caddy reload whenever I need to. It’s…not very elegant, but, works. PHP on the other hand, has a native package.

a. System environment:

root@FriendlyWrt:/sdcard# cat /etc/openwrt_release
DISTRIB_DESCRIPTION='OpenWrt 22.03.2 r19803-9a599fee93'
root@FriendlyWrt:/sdcard# cat /etc/openwrt_version

Device: FriendlyElec NanoPi R6S

b. Command:

# /etc/rc.local:
/usr/bin/caddy start --resume --config /srv/Caddyfile

# Later in shell:
caddy validate --config /srv/Caddyfile
caddy reload --config /srv/Caddyfile

c. Service/unit/compose file:

See above.

d. My complete Caddy config:

# Globals
        log {
                level info
                output file /var/log/caddy.log {
                        roll_size 10mb
                        roll_keep 10
                        roll_keep_for 720h

(php) {
        php_fastcgi unix//var/run/php8-fpm.sock {
                try_files {http.vars.root}/{path} {http.vars.root}/{path}/index.php

:80 {
        # Set this path to your site's directory.
        root * /srv/default

        # Enable the static file server.

        # Another common task is to set up a reverse proxy:
        # reverse_proxy localhost:8080

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000

# Basic ping-pong {
        respond "hello"

# LuCi {
        reverse_proxy * localhost:8080

# Home Assistant {
        reverse_proxy * localhost:8123

# TVHeadend - broken atm... {
        reverse_proxy * localhost:9981 {
                header_up X-Real-IP {remote_host}
                header_up X-Forwarded-For {remote_host}

# NextCloud {
        root * /sdcard/srv/nextcloud
        import php

Additionally, /etc/php8-fpm.d/www.conf:

user = www
group = www
listen = /var/run/php8-fpm.sock
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
access.log = /var/log/www.access.log
chdir = /

3. The problem I’m having:


root@FriendlyWrt:/sdcard/srv/nextcloud# ls -l
-rwxrwxrwx    1 www      www         158285 Nov 30  2021 setup-nextcloud.php
root@FriendlyWrt:/sdcard/srv/nextcloud# curl -v
> GET /setup-nextcloud.php HTTP/1.1
> Host:
> User-Agent: curl/7.86.0
> Accept: */*
< HTTP/1.1 404 Not Found
< Content-Type: text/html; charset=UTF-8
< Server: Caddy
< Status: 404 Not Found
< X-Powered-By: PHP/8.1.13
< Date: Sun, 11 Dec 2022 12:23:11 GMT
< Content-Length: 25
No input file specified.

In the Caddyfile you see me trying to utilize the http.vars.root placeholder - I added that before writing this question. But the error is the same with or without.

4. Error messages and/or full log output:

root@FriendlyWrt:/sdcard/srv/nextcloud# tail /var/log/caddy.log
{"level":"info","ts":1670760823.6982152,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//"]}
{"level":"info","ts":1670760823.6990283,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0x4000448310"}
{"level":"warn","ts":1670760823.6991317,"logger":"http","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
{"level":"info","ts":1670760823.7033687,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:/root/.local/share/caddy"}
{"level":"info","ts":1670760823.7033985,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
{"level":"info","ts":1670760823.7034645,"logger":"tls","msg":"finished cleaning storage units"}
2022/12/11 12:13:43.703 info    tls.cache.maintenance   stopped background certificate maintenance      {"cache": "0x400088b650"}
{"level":"info","ts":1670760823.7044778,"msg":"autosaved config (load with --resume flag)","file":"/root/.config/caddy/autosave.json"}
{"level":"info","ts":1670760823.704517,"logger":"admin.api","msg":"load complete"}
{"level":"info","ts":1670760823.7063136,"logger":"admin","msg":"stopped previous server","address":"localhost:2019"}
root@FriendlyWrt:/sdcard/srv/nextcloud# tail /var/log/www.access.log
- -  10/Dec/2022:21:57:16 -0200 "GET /setup-nextcloud.php" 404
- -  10/Dec/2022:21:58:09 -0200 "GET /setup-nextcloud.php" 404
- -  10/Dec/2022:21:58:12 -0200 "GET /setup-nextcloud.php" 404
- -  10/Dec/2022:21:58:58 -0200 "GET /setup-nextcloud.php" 404
- -  11/Dec/2022:10:04:31 -0200 "GET /setup-nextcloud.php" 404
- -  11/Dec/2022:10:13:49 -0200 "GET /setup-nextcloud.php" 404
- -  11/Dec/2022:10:22:50 -0200 "GET /setup-nextcloud.php" 404
- -  11/Dec/2022:10:23:11 -0200 "GET /setup-nextcloud.php" 404
root@FriendlyWrt:/sdcard/srv/nextcloud# tail /var/log/php8-fpm.log
[10-Dec-2022 21:56:11] NOTICE: exiting, bye-bye!
[10-Dec-2022 21:56:12] ERROR: failed to open access log (/usr/log/www.access.log): No such file or directory (2)
[10-Dec-2022 21:56:12] ERROR: failed to post process the configuration
[10-Dec-2022 21:56:12] ERROR: FPM initialization failed
[10-Dec-2022 21:57:07] NOTICE: fpm is running, pid 26789
[10-Dec-2022 21:57:07] NOTICE: ready to handle connections
[11-Dec-2022 10:04:22] NOTICE: Terminating ...
[11-Dec-2022 10:04:22] NOTICE: exiting, bye-bye!
[11-Dec-2022 10:04:23] NOTICE: fpm is running, pid 8631
[11-Dec-2022 10:04:23] NOTICE: ready to handle connections

The logs cover a little more time - but as you see, same error still.

5. What I already tried:

I had the idea of using a (php) placeholder to not constantly having to re-type this part of the config to set up my PHP based services. This is just my home router, so things are fully allowed to be messy :). Idealy, I wanted to have simple $service.{system.hostname} { root /srv/... import php }-ish blocks to just have a central Caddyfile to control the whole thing. As you see, a few reverse proxies are also here so I don’t have to memorize port numbers all the time. I have statically assigned * to my router and that works quite well. The big idea is to eventually upgrade this to a full reverse-proxy setup to where some services are available from outside (Home Assistant for cloud integrations being one) whilst others stay in a cozy VPN.

So… that should be all the details. I am out of ideas…

6. Links to relevant resources:

None I could think of. o.o

I found the issue.

First, I enabled stderr catching in the pool configuration (catch_workers_output = yes), then also used capture_stderr true in my PHP block in the Caddyfile. And this produced this very error:

==> php8-fpm.log <==
[11-Dec-2022 11:07:26] WARNING: [pool www] child 18297 said into stderr: "ERROR: Unable to open primary script: /sdcard/srv/nextcloud/index.php (No such file or directory)"

Odd, it’s there.

# ls -l /sdcard/srv/nextcloud/index.php
-rw-r--r--    1 www      www             17 Dec 11 10:40 /sdcard/srv/nextcloud/index.php

Well… this gave me an idea. I did see chroot as an option in the FPM config - but those settings are mostly derived from the main php.ini, and those do take preceedence. So, I checked:

root@FriendlyWrt:/# cat /etc/php.ini | grep chroot
root@FriendlyWrt:/# cat /etc/php.ini | grep chdir
root@FriendlyWrt:/# cat /etc/php.ini | grep root
;docref_root = "/phpmanual/"
doc_root = "/www"

…now that’s a problem. Because doc_root will always be prepended to the path sent to PHP-FPM! Commented it and voila, it works. What an absolutely stupid error x). Since OpenWrt’s LuCi interface lives in /www, I am pretty sure that they intended the package to be used with the default uhttpd

Anyway, I am leaving this answer here for the case that another poor soul runs circles about this. :slight_smile:


Thank you for following up with the solution!

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