0

Disclaimer: I've tried tips listed in probably every google result on the first 2 pages. None of them worked for me. This is not a duplicate.

I'm running Debian 9 in LXC container that had LAMP installed, today I wanted to replace apache2 with php-fpm and nginx. The problem is that I can't get this config to work at all.

The "default" virtual host is disabled (file/symlink not present in sites-enabled)

Current config (sites-enabled/phpmyadmin):

server {
    listen 127.0.0.1:80;
    root /home/fakeuser/fakepath;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name _;

    location ~\.php$ {
            include snippets/fastcgi-php.conf;
            #fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/$fastcgi_script_name;
            fastcgi_pass  unix:/run/php/php7.0-fpm-phpmyadmin.sock;
            include fastcgi_params;
    }

    location /phpmyadmin {
        alias /usr/share/phpmyadmin;

        location ~\.php$ {
            include snippets/fastcgi-php.conf;
            #fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/$fastcgi_script_name;
            fastcgi_pass  unix:/run/php/php7.0-fpm-phpmyadmin.sock;
            include fastcgi_params;
        }
    }

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
    }
}

When I try to open:

localhost/index.php

I get index.php downloaded to my pc

when I try to open:

localhost/phpmyadmin/index.php

I get "File not found." and this entry in

/var/log/nginx/error.log


2018/09/17 19:22:37 [error] 27804#27804: *4 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET /phpmyadmin/index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm-phpmyadmin.sock:", host: "localhost"

UPDATE: I've checked log of php-fpm, and it just prints this into log every time:

- - 20/Sep/2018:21:03:26 +0000 "GET /phpmyadmin/index.php" 404

I have no idea what I'm doing wrong, www-data user have access to everything in that directory, I've checked 5 times by now.

Kristi
  • 91
  • 2
  • 10

1 Answers1

0

Looking at your configuration I'm not sure that your nginx directives fastcgi_pass and fastcgi_param are correct.

try something simpler like this:

location ~* \.php$ {
    include /etc/nginx/fastcgi.conf;
    include /etc/nginx/fastcgi_params;
    fastcgi_index index.php;
    fastcgi_pass 127.0.0.1:9000;
   }

if your php-fpm is listening on port 9000 or point it to a correct socket path (defined in fpm conf file)

Also please check it file /run/php/php7.0-fpm-phpmyadmin.sock exists. I'm under the impression that the default php7 socket path is unix:/run/php/php7.0-fpm.sock. There may be other things you need to check as php.ini. Please try to follow nginx how to section of this tutorial: https://www.howtoforge.com/tutorial/installing-nginx-with-php7-fpm-and-mysql-on-ubuntu-16.04-lts-lemp/

Roman Spiak
  • 583
  • 3
  • 11
  • Still the same `2018/09/19 20:01:46 [error] 2610#2610: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET /phpmyadmin/index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm-phpmyadmin.sock:", host: "localhost" ` – Kristi Sep 19 '18 at 20:03
  • this line indicates that you have not changed the configuration as I recommended: `request: "GET /phpmyadmin/index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm-phpmyadmin.sock:", host: "localhost"` – Roman Spiak Oct 09 '19 at 08:17