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 (#)
I my case I was not using
/etc/nginx/sites-available/default
I was using a different server block configuration file (e.g. example.com), and the only way I was able to fix this problem is by removing the default server block configuration file symbolic link:then reloading Nginx:
If anything else doesn't help you. And maybe earlier you installed apache2 with info.php test file. Just clear App Data (cache,cookie) for localhost.
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.
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:
Restart Nginx and PHP services
sudo systemctl restart php-fpm
andsudo systemctl restart nginx
.Last but most important, clear browser cache or running in
incognito (Chrome)
orPrivate Browsing (Firefox)
etc...Hope this helpful and happy coding
Try this:
Edit
/etc/nginx/sites-available/default
Uncomment both listen lines to make nginx listen on port 80 IPv4 and IPv6.
Leave
server_name
aloneAdd
index.php
to theindex
lineUncomment
location ~ \.php$ {}
Edit
/etc/php5/fpm/php.ini
and make surecgi.fix_pathinfo
is set to0
Restart nginx and php5-fpm (if you don't know how to do it, restart the server)
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.
I had similar problem which was resolved by emptying the browser cache (also worked fine with different browser).
For me it helped to add
?$query_string
at the end of /index.php, like below: