3

I am apparently not the only one with this problem, but after trying every suggested solution for couple I reached I point where I don't know what to do.

I am running Ubuntu 16.04, NGinx and PHP-FPM.

The nginx.conf is the default one, I only set a more informative log format.

The user rights seem to be okay: NGinx and PHP_FPM run under user www-data. Document-Root owner is www-data. FPM-Pool owner is www-data. Socket-file is there and writable.

I already tried setting folder- and file-permissions to the weakest (chmod 777): No result.

This is my server.conf, as you can see from commented lines, I tried a bunch of tricks - with no effect:

server {
    listen         8080;
#    listen         8080 default_server;
 #   listen         [::]:8080 default_server;
    server_name    example.com www.example.com
    root           /var/www/nginx/;
    index          index.php;
        access_log /var/log/nginx/scripts.log scripts;


    gzip             on;
    gzip_comp_level  3;
    gzip_types       text/plain text/css application/javascript image/*;

    location ~ \.php$ {
        if ($uri !~ "^/uploads/") {
            fastcgi_pass unix:/run/php/php-fpm-www.sock;

        }

    include fastcgi.conf;

#    include         snippets/fastcgi-php.conf;
    include         fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;

  }

    # Block access to .htaccess
    location ~ \.htaccess {
        deny all;
    }

}    

That's the fpm-pool config:

[www]
listen = /run/php/php-fpm-$pool.sock
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
php_admin_flag[allow_url_fopen] = off
php_admin_flag[allow_url_include] = off
php_admin_value[memory_limit] = 128M
pm = dynamic
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /
chroot = /var/www/nginx/
php_flag[display_errors] = on
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
catch_workers_output = yes

This is the output of the nginx' access.log:

/var/www/nginx/index.php > GET /index.php HTTP/1.1

And that's the actual error.log:

2018/08/29 17:34:27 [error] 24020#24020: *47 FastCGI sent in stderr: "Unable to open primary script: /var/www/nginx/index.php (No such file or directory)" while reading response header from upstream, client: 213.61.37.18, server: example.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php-fpm-www.sock:", host: "example.com:8080"
  • 1
    chmod will not help with No such file or directory. The problem is you chrooted php-fpm. – Michael Hampton Aug 29 '18 at 16:40
  • @MichaelHampton - I am aware of that, but it looks like I did not understand the effects. I found the solution, will post it in a second, thank you! – n.r. Aug 30 '18 at 9:06
1

I found the error for myself after the hint of @michael - thanks for the enlightenment.

I am using chroot, because the goal is to "jail" every website in it's own environment / folder. So I set the root of this particular environment to the real filesystem location /var/www/nginx.

Inside the server configuration of NGinx I pass the fastcgi parameter SCRIPT_FILENAME with a leading $document_root.

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

In NGinx $document_root references the root-directive. The $document_root is, of course /var/www/nginx

But the PHP-environment has a "changed root" (/ means /var/www/nginx). That means, that PHP now is looking for index.php in the folder /var/www/nginx. But as the root folder is only "virtual", PHP's /var/www/nginx actualy points to this location on the real filesystem: /var/www/nginx/var/www/nginx.

So changing the parameter to this will fix the error.

fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.