Primary script unknown

Hi,

I am new to Caddy. Trying out got into some trouble. Have gone through the wiki : https://github.com/mholt/caddy/wiki/Troubleshooting-PHP-FPM-and-FastCGI , but seems the issue is not mentioned there.

Mostly the problem is as reported in https://github.com/mholt/caddy/issues/611 . I tried some of the options it mentioned, but not successful.

These are the configurations I tried

localhost:8080
tls off
ext .html   # Clean URLs
errors {
    log errors.log    # Error log
    404 error-404.html   # Custom error page
}
fastcgi / /var/run/php5-fpm.sock php {
    ext     .php
    split   .php
    index   index.php
}
localhost:8080 {
   log access.log
   errors error.log

    # PHP-FPM with Unix socket
    fastcgi / /var/run/php5-fpm.sock php {
        ext     .php
        split   .php
        index   index.php
        listen = /var/run/php5-fpm.sock
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }    
}

Running caddy as root.

The error.log always mentions Primary script unknown .

The accesslog shows 404. Browser also show File not found.

Thank you

First of all, all this:

        ext     .php
        split   .php
        index   index.php

is redundant since you’re using the php preset.

Also,

        listen = /var/run/php5-fpm.sock
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

These look like they belong in an nginx.conf, not a Caddyfile. (Maybe we need stricter parsing? Regardless, it’s invalid.)

You can reduce what you need to:

fastcgi / /var/run/php5-fpm.sock php

Anyway, it’s probably something wrong with your system or php-fpm config. Also make sure your root is properly set.

1 Like

Good to know . Was taking those from the docs. copy paste :slight_smile: .

Good to know.

Yes that was the only one earlier, but as it didn’t worked, I was adding more configration values to test things.

Currently nginx is using some what similar configuration and it works, so not sure what may be wrong with the php-fpm though.

Thanks.

Try running caddy as non root and/or move the source files from root owned directory.

Looks like php-fpm can’t read the source files.

2 Likes

I had this issue before, the solution is to run caddy and php-fpm under the same user/group and make sure Caddy’s user/group can read the document root folder (chmod?).

Here’s the issue I opened in case you want to check it:
https://github.com/mholt/caddy/issues/190#issuecomment-130536608

Perhaps we should edit the wiki :slight_smile:

2 Likes

That would be great, if you would. :wink:

Done, didn’t add a very detailed explanation but should be enough for most people. Whoever is reading this feel free to enhance it :slight_smile:

After much struggle I was able to run Caddy.

What I did was add www-data to the user .

sudo usermod -a -G groupName userName

You can read more from

How to add existing user to an existing group? - Ask Ubuntu .

One remaining thing that bites me is when I do a post request it reports 2016/08/01 20:57:39 http: multiple response.WriteHeader calls .

This is how my Caddfile looks like

localhost:8000
gzip
tls off
root /path/to/public
fastcgi / /var/run/php/php7.0-fpm.sock php
rewrite {
    to {path} {path} /index.php?{query}
}

Once I am able to fix, I hope I can send a PR for some of the php projects.

Thank you :slight_smile: .

I have found the problem, it was basically mentioned over https://github.com/mholt/caddy/issues/988 , not a caddy bug. But better error reporting can help.

1 Like

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