Score:0

Browser downloads the file instead of opening php files

br flag

So, I'm posting an answer, because after the twice clean-reinstall, I have set things a but differently (to my point of view). Like I said above, I face a dilemma, since none of the config I have is the same as to any other answers I could find. For instance :

My /etc/nginx folder is basically constituted as followed :

|- /etc/nginx/
|  |- conf.d/
|  |  |- default.conf
|  |
|  |- fastcgi_params
|  |- mime.types
|  |- modules/ -> /usr/lib/nginx/modules
|  |- nginx.conf
|  |- scgi_params
|  |- uwsgi_params

There is no /sites-available or /sites-enabled as seen everywhere, the mentioned fastcgi-php.conf is actually a fastcgi_params in the root folder, my default hence is not in the site-available folder.

Here are the two configs files I now have (domain hidden under my_domain.com): First : the nginx.conf (almost untouched)

    user  nginx;

worker_processes  auto;

error_log  /var/log/nginx/error.log notice;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;

}

http {
    include       /etc/nginx/mime.types;
    include       /etc/nginx/sites-available/*.conf;
    default_type  application/octet-stream;


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';



    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    include /etc/nginx/conf.d/*.conf;

}

Secondly the /etc/nginx/conf.d/default.conf

    server {
    listen       80;
    server_name  my_domain.com www.my_domain.com;

    location / {
        root /var/www/www.my_domain.com;
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /var/www/www.my_domain.com;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        #if (!-f $document_root$fastcgi_script_name) {
        #    return 404;
        #}
        root           /var/www/www.my_domain.com;
    #    fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }
    

}

I also added a line

text/php            php;

to the mime.types I also remember to delete the cache of my_domain in the browsers I use (Firefox, Opera and Chrome).

But still, the file is downloaded.

What did I do wrong ?

Edit : as I would like to make a blog.my_domain.com, shop.my_domain.com and forum._mydomain.com, I created the /site-available and /site-enabled folder, intend to create a blog/forum/shop.my_domain.com.conf in each folder of the same name located in the /sites-available, but I'm awaiting for a working config to make them visible in the nginx.conf (with an include line, right ?).

So I don't really get how these two folders work. The subdomains have their CNAME record set to my_domain.com. I also read about making a symlink for these sub-websites, but I don't really know from where to where ? Thanks again

The error log tells me the connection to /var/run/php/ is denied. the default user is www-data www-data, but my defaut nginx user is nginx (if I change it, it doens't even start.) Should I make a

chown nginx:nginx /var/run/php/

?

Score:0
th flag

To configure php you have to have an version of php-fpm installed on your system. And add this snippet to your nginx conf in the server block.

You have to change php5-fpm to the version you have installed on your system.

  location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
Kl3m Michard avatar
br flag
Thanks, I'll try that in a minute. Sorry for the delay, I had to clean-reinstall twice before getting there again. Can I trouble you for some more explanations ? I'll post them below as an answer for more practicality.
Score:0
gu flag

You lack a PHP interpreter, NGINX has an article on its wiki about FPM.

Kl3m Michard avatar
br flag
Thanks, but I've followed their instructions on that page. Still no change. I'm not an experimented coder, most of what they say is like gibberish to me. Would someone care to explain it a bit more ? Thanks a lot.
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.