Viewed   126 times

I am installing a website in a droplet (Digital Ocean). I have a issue for install NGINX with PHP properly. I did a tutorial https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04 but when I try to run some .php file it's just downloading it... for example... http://5.101.99.123/info.php it's working but... If I go to the main http://5.101.99.123 it's downloading my index.php :/

Any idea?

-rw-r--r--  1 agitar_user www-data   418 Jul 31 18:27 index.php
-rw-r--r--  1 agitar_user www-data    21 Aug 31 11:20 info.php

My /etc/nginx/sites-available/default

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/html;
        index index.html index.htm index.php;

        # Make site accessible from http://localhost/
        server_name agitarycompartir.com;

               location ~ .php$ {
                    fastcgi_split_path_info ^(.+.php)(/.+)$;
    ## NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #               # With php5-cgi alone:
    #               fastcgi_pass 127.0.0.1:9000;
    #               # With php5-fpm:
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
            }
  

              location / {
                    
                    try_files $uri $uri/ =404;
                    # Uncomment to enable naxsi on this location
                    # include /etc/nginx/naxsi.rules
            }

...

Others "location" are commented...

.

 Answers

2

Try this:

  1. Edit /etc/nginx/sites-available/default

  2. Uncomment both listen lines to make nginx listen on port 80 IPv4 and IPv6.

    listen   80; ## listen for ipv4; this line is default and implied
    listen   [::]:80 default_server ipv6only=on; ## listen for ipv6
    
  3. Leave server_name alone

    # Make site accessible (...)
    server_name localhost;
    
  4. Add index.php to the index line

    root /usr/share/nginx/www;
    index index.php index.html index.htm;
    
  5. Uncomment location ~ .php$ {}

    # pass the PHP scripts to FastCGI server listening on (...)
    #
    location ~ .php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    
            # With php5-cgi alone:
            #fastcgi_pass 127.0.0.1:9000;
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }
    
  6. Edit /etc/php5/fpm/php.ini and make sure cgi.fix_pathinfo is set to 0

  7. Restart nginx and php5-fpm sudo service nginx restart && sudo service php5-fpm restart


I have just started using Linux a week ago, so I really hope to help you on this. I am using nano text editor to edit the files. run apt-get install nano if you don't have it. Google on it to know more.

Wednesday, October 19, 2022
4

Try to change default_type application/octet-stream; to default_type text/html; Maybe your php-script does not set a content MIME type and it goes from nginx.

Saturday, November 19, 2022
 
vitus
 
1

Sounds like your environment hasn't got PHP installed.

Do you have anymore information about it?

Thursday, September 1, 2022
 
nan_yu
 
4

You could use a regular expression location to capture the first part of the URI, for example:

location ~ ^(/[^/]+) {
    try_files $uri $uri/ $1/index.php?$args;
}

Or use a named location with one or more rewrite statements, for example:

location / {
    try_files $uri $uri/ @rewrite;
}
location @rewrite {
    rewrite ^(/[^/]+) $1/index.php last;
}
Saturday, August 6, 2022
4

CGI::Fast will handle most of the work for you, including setting up the daemon.

use CGI::Fast;

local $ENV{FCGI_SOCKET_PATH} = ":9000";
local $ENV{FCGI_LISTEN_QUEUE} = 20;

while ($q = CGI::Fast->new) {
    print $q->header;
    print "<html><body>The foo input is ", $cgi->param('foo'), "</body></html>";
}

An alternative is Nginx::Simple which gives you more control over the behavior of your cgi-script-as-daemon.

Friday, December 9, 2022
 
lostlin
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :