Can't get PHP 7.0 to work with NGINX

It seems like I just can’t wrap my head around setting up nginx to work with php7.0-fpm on my Raspberry Pi with a Raspbian based distribution, called DietPi. All the guides and tutorials I read make it seem like it is super easy and it should work within minutes, but none of them worked, not even remotely.

My .vhost file for an otherwise working nginx server/proxy:

server {
    resolver 1.1.1.1;
    server_name mydomain.tld;
    error_page 404 /mypath/404.html;
    
    include /etc/nginx/mime.types;
    
    index index.php;
    
    location ^~ /css {
        default_type text/css;
    }
    
    location = /404.html {
       allow all;
       internal;
    }
    
    location /srv1 {
       root /var/;
       autoindex on;
    }
    
    location /srv2 {
       set $upstream "127.0.0.1:1000";
       proxy_pass http://$upstream/;
    }
    
    
#    location /php {
#       alias /mypath;
#      try_files $uri $uri/ =404;
#    
#          location ~ /php/\.php(?:$|/) {
#          fastcgi_split_path_info ^(.+\.php)(/.+)$;
#          fastcgi_param PATH_INFO $fastcgi_path_info;
#          fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#          fastcgi_index index.php;
#          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#          include fastcgi_params;
#       }
#    
#       location ~ /php/\.ht {
#          deny all;
#       }
#    
#    }

 location /php/ {
 
    alias /mypath;
    
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
       try_files $uri $uri/ =404;
    
     
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ /php/\.php$ {
       include snippets/fastcgi-php.conf;
        
    # With php7.0-cgi alone:
    # fastcgi_pass 127.0.0.1:9000;
    # With php7.0-fpm:
       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
              
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
       location ~ /\.ht {
       deny all;
    }
    }
        
    location / {
       set $upstream "127.0.0.1:2000";
       proxy_pass http://$upstream;
    }
    
    
   
    access_log  /var/log/nginx/srv2.access.log;
    error_log   /var/log/nginx/srv2.error.log;
    

    listen 443 ssl; # managed by Certbot
    ssl_certificate /mypath/mydomain.tld/fullchain.pem; # managed by Certbot
    ssl_certificate_key /mypath/mydomain.tld/privkey.pem; # managed by Certbot
    include /mypath/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /mypath/ssl-dhparams.pem; # managed by Certbot

}server {
    if ($host = mydomain.tld) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name mydomain.tld;
    return 404; # managed by Certbot
    
}

This is the .vhost file for the server(s). All the blocks not related to the PHP configuration are there for informational purposes, since I can’t exclude they interfere with the PHP situation, but be assured that they work on their own without issues.

The special thing about this configuration is, that I don’t want to make a server-block-wide root location, because I host several ones on this address and the TLD root is already taken.

When you hit your IP you can see a normal htm page so if you hit your phpinfo page, what shows up in the log?

1 Like

@wadesmart Are you talking about the nginx log or some other log I am not thinking of right now?

Yes. You can look in your main log. When I was running a pi server I ran apache and the logs were of much help