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 (#)
Update nginx config /etc/nginx/sites-available/default or your config file
if you are using php7 use this
if you are using php5 use this
Visit here for complete detail Detail here
My solution was to add
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.Then open terminal and run the following command:
Then add the following code in the
default
file:If any mismatch just correction and restart Nginx from terminal by the following command
Then go to browser and Enjoy ...
If any of the proposed answers is not working, try this:
1.fix www.conf 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
5.restart php service
6.enjoy
I am using Ubuntu 14.04
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.
check your nginx config file extension is *.conf.
for example: /etc/nginx/conf.d/myfoo.conf
I got the same situation. After I rename the my config file from myfoo to myfoo.conf, it fixed. Do not forget to restart nginx after rename it.