I see that there are several closed issues involving php-fpm, but none of them have helped me.
I believe I have php-fpm configured and running correctly, but I keep getting [ERROR 404 /] Primary script unknown errors when trying to access any PHP files. The user running caddy is a member of the group http, which is the owner and group configured for php-fpm in Arch.
Caddyfile:
localhost:8080
errors error.log
fastcgi / 127.0.0.1:9000 php
PHP-FPM configs: https://gist.github.com/jacobmischka/30d328f4e58717cda1db
$ ps aux | grep php-fpm
root 3260 0.0 0.1 266528 30128 ? Ss 11:14 0:00 php-fpm: master process (/etc/php/php-fpm.conf)
http 3262 0.0 0.0 266528 8192 ? S 11:14 0:00 php-fpm: pool www
http 3263 0.0 0.0 266660 11264 ? S 11:14 0:00 php-fpm: pool www
mischka 3474 0.0 0.0 10728 2304 pts/1 S+ 11:18 0:00 grep php-fpm
$ netstat -an | grep :9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
Add root to your Caddyfile. Caddy may be started from the wrong directory.
root /path/to/php/source/files
I'm running caddy from the directory that the php files are in, but I've added root, still doesn't seem to work.
Caddyfile:
localhost:8080
errors error.log
root /home/mischka/Downloads/dokuwiki
fastcgi / 127.0.0.1:9000 php
/home/mischka/Downloads/dokuwiki/test.php:
<?php
phpinfo();

What about the permissions of the files. Are they readable by php-fpm and what do you have in error log ?
They should be readable, yes. I'm particularly confused as to why it's throwing a 404 error and not a 500 level one. Non-PHP files are showing up fine. I've never used php-fpm before, so I may well be doing something wrong, but I believe the configuration is correct. If you could take a look at them to confirm that that would be great.
-rw-r--r-- 1 mischka http 18 Feb 17 11:31 test.php
error.log:
17/Feb/2016:13:15:28 -0600 [ERROR 404 /] Primary script unknown
17/Feb/2016:13:15:32 -0600 [ERROR 404 /test.php] Primary script unknown
My system logs when starting php-fpm:
Feb 17 13:23:04 mischka-work systemd[1]: Started The PHP FastCGI Process Manager.
Feb 17 13:23:04 mischka-work php-fpm[8527]: [NOTICE] systemd monitor interval set to 10000ms
Feb 17 13:23:04 mischka-work php-fpm[8527]: [NOTICE] ready to handle connections
Feb 17 13:23:04 mischka-work php-fpm[8527]: [NOTICE] fpm is running, pid 8527
Feb 17 13:23:04 mischka-work systemd[1]: Starting The PHP FastCGI Process Manager...
Feb 17 13:23:04 mischka-work systemd[1]: Stopped The PHP FastCGI Process Manager.
Feb 17 13:23:04 mischka-work php-fpm[3535]: [NOTICE] exiting, bye-bye!
Feb 17 13:23:04 mischka-work php-fpm[3535]: [NOTICE] Terminating ...
Feb 17 13:23:04 mischka-work systemd[1]: Stopping The PHP FastCGI Process Manager...
Feb 17 13:23:04 mischka-work polkitd[407]: Registered Authentication Agent for unix-process:8520:1009586 (system bus name :1.128 [/usr/bin/pkttyagent --notify-f
Feb 17 13:23:04 mischka-work sudo[8518]: pam_unix(sudo:session): session opened for user root by (uid=0)
Feb 17 13:23:04 mischka-work sudo[8518]: mischka : TTY=pts/0 ; PWD=/home/mischka/Downloads/dokuwiki ; USER=root ; COMMAND=/usr/bin/systemctl restart php-fpm
This is strange. Seeing this the first time.
What platform are you on ?
Arch Linux x64, kernel 4.4.1-2-ARCH.
php 7.0.3-1, php-fpm 7.0.3-1, caddy 0.8.1-1
Did you see https://github.com/mholt/caddy/wiki/Troubleshooting-PHP-FPM-and-FastCGI? Any of those tips help?
I did, and I believe I've been through them all. I've tried both a unix socket and a TCP port for php-fpm's listener. My error message doesn't match any of those examples and I can't see anything in php-fpm's configs that's wrong.
If you don't mind. You can mail me temporary ssh details to the server and let me help with troubleshooting.
I have not been able to reproduce it in my own environments.
Can you do the following commands just to be sure that the http user can go through all directories of the Root Dir:
ls -ld /home/mischka/Downloads/dokuwiki
ls -ld /home/mischka/Downloads/
ls -ld /home/mischka/
ls -ld /home/
@abiosoft Unfortunately I can't, it's my development computer on my employer's network, it doesn't allow incoming connections.
I'll try setting it up on my personal computer tonight or tomorrow and if I run into the same problem I'll send you ssh info. Thanks for trying, I must have done something wrong but I can't figure out what it is.
Okay well, turns out Downloads wasn't readable, but I've moved it out and it's still giving me the same error. https://gist.github.com/jacobmischka/dc75426d172f37c82d10
I moved it to the regular http server location but I'm still getting the same thing. https://gist.github.com/jacobmischka/43a58335f7fd80df3532
23/Feb/2016:08:50:08 -0600 [ERROR 404 /test.php] Primary script unknown
23/Feb/2016:08:54:49 -0600 [ERROR 404 /test.php] Primary script unknown
23/Feb/2016:08:55:24 -0600 [ERROR 404 /test.php] Primary script unknown
23/Feb/2016:08:55:31 -0600 [ERROR 404 /test.php] Primary script unknown
23/Feb/2016:08:58:21 -0600 [ERROR 404 /test.php] Primary script unknown
test.php is readable as well
-rw-r--r-- 1 mischka http 18 Feb 17 11:31 test.php
This page says it's due to a wrongly set "SCRIPT_FILENAME" variable. It should be whatever the absolute path to that test.php file is. @jacobmischka We're still having trouble reproducing this, do you have Go installed?
I do yes
@jacobmischka Cool, it'd be helpful if we could see the value of the vars like SCRIPT_FILENAME (this whole env map would be good) -- I think that'd be a good start.
Well, I haven't looked at this since my last comment, but it's actually working now. Either I needed to reboot after installing php-fpm and I hadn't done that, or I'm an idiot and I forgot to edit the root path after moving it out of the non-readable Downloads folder.

I am very sorry for all of the confusion. Thank you all for your help.
Oh, great to hear :+1:
Just to help someone else out:
I had the exact same error and fixed it by changing the user/group in /usr/local/etc/php/7.0/php-fpm.d/www.conf to my own user and group. I then restarted php-fpm with
sudo brew services stop php-fpm.
brew services start php-fpm
Here is my Caddyfile:
# Your site's address
# The http:// part makes caddy listen on port 80
# You need sudo to start caddy on port 80
http://testsite.local
# Disable https
# The bootup letsencrypt stuff doesn't like .local domain suffix
tls off
ext .html # Clean URLs
errors {
log ../errors.log # Error log
404 error-404.html # Custom error page
}
# php-fpm is configured on 9001 so as to not collide with xdebug which defaults on 9000
fastcgi / localhost:9001 php {
ext .php
split .php
index index.php
}
# Rewrite rules to work with slim framework and alike
rewrite {
r .*
ext /
to /index.php?{query}
}
I run it from within my public directory with sudo caddy --conf=../Caddyfile
Note that you don't need tls off if you specify http:// in the address of the site. ;)
Nor do you need ext .php split .php index index.php in your fastcgi directive if you suffix that first line with php - it's redundant.
Just in case somebody cannot solve the Primary script unknown problem with the above solutions. Be sure SELinux is disabled. That fixed it in my case.
Most helpful comment
Just to help someone else out:
I had the exact same error and fixed it by changing the user/group in /usr/local/etc/php/7.0/php-fpm.d/www.conf to my own user and group. I then restarted php-fpm with
Here is my Caddyfile:
I run it from within my public directory with sudo caddy --conf=../Caddyfile