1

I just configured my Debian 8 server with nginx. I can browse html files. I use let's encrypt which works succesfully, also with redirecting http to https automatically.

What does not work is PHP. Also a simple info.php file with

<?php
  phpinfo();
?>

does not work.

On browser client my error message is:

404 Not Found nginx/1.6.2

Nginx' error log shows this:

2018/05/29 19:22:57 [error] 1879#0: *1592 open() "/usr/share/nginx/html/info.php" failed (2: No such file or directory), client: ip_address, server: , request: "GET /info.php HTTP/1.1", host: "domain"

My nginx configuration is:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    server_name my-server.de www.my-server.de;
    return 301 https://$server_name$request_uri;

    root /var/www/html;

    index index.php index.html index.htm index.nginx-debian.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ /.php$ {
        include snippets/fastcgi-php.conf;

        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    include snippets/ssl-my-server.de.conf;
    include snippets/ssl-params.conf;
}

Even if i move info.php to /usr/share/nginx/html then the client browser just downloads the info.php file.

I went through all steps in this guide. But still it isn't working. So how to fix that?

3
  • 1
    Of course I did Commented May 29, 2018 at 17:47
  • Did you restart web server after changing nginx config, and php-fpm? make sure you should give 777 permission to /var/run/php5-fpm.sock Commented May 29, 2018 at 17:48
  • I tried that too: same problem Commented May 29, 2018 at 17:55

2 Answers 2

1

You have not added in SSL listen port 443, and ssl config of let's encrypt, please comment 301 redirect, test PHP, than go for SSL configuration see https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-debian-8

I have seen you have added SSL configuration, you need fix as below nginx configuration, after redirect, PHP should be configured on 443 not on 80.

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name my-server.de www.my-server.de;
    # Redirect to HTTPS    
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    include snippets/ssl-my-server.de.conf;
    include snippets/ssl-params.conf;


    root /var/www/html;

    index index.php index.html index.htm index.nginx-debian.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ /.php$ {
        include snippets/fastcgi-php.conf;

        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for accepting answer, I see PHP 5 is now running, :)
0

This is what I'm using:

    upstream php {
            server 127.0.0.1:9000;
            server unix:/var/run/php5-fpm.sock down;
    }


    location ~* \.php$ {
            root /var/www/html/;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_read_timeout 180;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

            include fastcgi_params;
            fastcgi_pass php;
            fastcgi_index index.php;
    }

3 Comments

Applying this does not change anything for me. I don't understand why don't find any solution for such a typical use-case?
@unlimited101 Have you put it in the correct server { ... } block? Can you paste your current/changed config?
Sure I put it in the upper block and removed this block: location ~ /.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php5-fpm.sock; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.