Score:0

Nginx downloads me PHP files instead of executing them

br flag

I am using Nginx for my web server, but when I go to a PHP page it downloads it to me.
I realized that my pterodactyl panel (which is in php) was still working, so I used the fastcgi and other parts of its config, without this changing my problem
I have Nginx last version and PHP 8.0 installed on a Debian 11 VPS.
The files are under permission 775 and owned by the group www-data. The logs aren't giving me any reason for this problem.

server {
    listen 80;
    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html/site;
    index index.html index.php index.htm index.nginx-debian.html;
    server_name mondomaine.eu www.mondomaine.eu;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }


    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTP_PROXY "";
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
    }

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

Can you help please? Thanks

Paul avatar
cn flag
Is your domain `mondomaine.eu`?
djdomi avatar
za flag
verify with https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/ more over verify that the socket exists and the daemon running from php fpm, i am unsure but wasnt it /var/run instead /run?
Paul avatar
cn flag
@djdomi Depending on the OS, `/var/run` may be symlinked to `/run`.
coera avatar
br flag
Hey! Well, I just edited the domain, it's not that one in reality and DNS are working. Then, the path to PHP FPM works, but when trying to access /run/php/php8.0-fpm.sock, I have a permission denied error even though the permission is 775.
Paul avatar
cn flag
The ownership and permissions of `php8.0-fpm.sock` should be `www-data:www-data` usually with `660` permissions.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.