Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 808 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nginx serves .php files as downloads, instead of executing them

#1
I am installing a website in a droplet (Digital Ocean). I have an issue for install NGINX with PHP properly. I did a tutorial

[To see links please register here]

but when I try to run some .php files 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

[To see links please register here]

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
}
...

Other "locations" are commented on...



.

Reply

#2
The answer above seemed to comment out too much for the solution I reached. This is what my file looked like:

/etc/nginx/sites-available/default

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;
}

Hope this helps some folks who are frustrated on a sunday afternoon (c:
Reply

#3
What worked for me with Ubuntu 16.04, and php7 was deleting this line

`fastcgi_split_path_info ^(.+\.php)(/.+)$;`

It stopped downloading php files after that.
Reply

#4
If any of the proposed answers is not working, try this:

##1.fix

[To see links please register here]

in etc/php5/fpm/pool.d:
`listen = 127.0.0.1:9000;(delete all line contain listen= )`
##2.fix nginx.conf in usr/local/nginx/conf:
`remove server block server{} (if exist) in block html{} because we use server{} in default (config file in etc/nginx/site-available) which was included in nginx.conf.`
## 3. fix default file in etc/nginx/site-available
`location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}`
##4.restart nginx service
>sudo service nginx restart

##5.restart php service
>service php5-fpm restart

##6.enjoy
>Create any php file in /usr/share/nginx/html and run in "server_name/file_name.php"
(server_name depend on your config,normaly is localhost, file_name.php is name of file which created in /usr/share/nginx/html ).


I am using Ubuntu 14.04
Reply

#5
I had similar problem which was resolved by **emptying the browser cache** (also worked fine with different browser).
Reply

#6
For anyone having same issue with PHP 7, this is what I done to make nginx execute php files properly in CentOS 7, posted here so in case of anyone having same problem:

- Follow step by step this document on [Digital Ocean][1].

- Open the `/etc/nginx/conf.d/default.conf` (by default I don't have sites-enabled nor sites-available, you can edit accordingly).

- Edit the `location` parameter as below:


*default.conf*:



location ~ \.php$ {
try_files $uri =404;
#fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

#instruct nginx execute php7 files instead download them :D
fastcgi_pass unix:/var/run/php-fpm/www.sock;

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

- Restart Nginx and PHP services `sudo systemctl restart php-fpm` and `sudo systemctl restart nginx`.

- Last but most important, clear browser cache or running in `incognito (Chrome)` or `Private Browsing (Firefox)` etc...

Hope this helpful and happy coding


[1]:

[To see links please register here]


Reply

#7
**Update nginx config /etc/nginx/sites-available/default or your config file**

if you are using php7 use this

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

if you are using php5 use this

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

Visit here for complete detail [Detail here][1]


[1]:

[To see links please register here]

Reply

#8
**Uncomment the \.php location in /etc/nginx/sites-available/default**

> sudo vi /etc/nginx/sites-available/default:


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

# With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
Reply

#9
My solution was to add

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
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;

to my custom configuration file, for example `etc/nginx/sites-available/example.com.conf`

Adding to `/etc/nginx/sites-available/default` didn't work for me.
Reply

#10
I had the same issue and none of the answers solved the problem.

I ran:

sudo nginx -t

to test the config file at /etc/nginx/sites-available/default.

It gave me these errors:

nginx: [emerg] unexpected end of file, expecting "}" in /etc/nginx/sites-enabled/default:115
nginx: configuration file /etc/nginx/nginx.conf test failed

So I went into the config file and on the last line there was

#}

I uncommented, ran the test command again and it worked



Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through