Nginx serves .php files as downloads, instead of executing them
Try this:
Edit
/etc/nginx/sites-available/default
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 ipv6Leave
server_name
alone# Make site accessible (...)
server_name localhost;Add
index.php
to theindex
lineroot /usr/share/nginx/www;
index index.php index.html index.htm;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;
}Edit
/etc/php5/fpm/php.ini
and make surecgi.fix_pathinfo
is set to0
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.
NGINX downloads PHP file instead of showing
Please try this smaller example.
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
And double check if your php-fpm is running:
sudo systemctl status php7.1-fpm.service
Php file gets downloaded instead of executing on OSX with Nginx server
root html;
must be changed with path to your web,
root /Users/username/Sites;
replace with this in your location php section:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Nginx downloads php instead of running it
I just had this exact same problem. I was using Ubuntu 12.04 and Linux Mint 14 so different OS but likely to have the same issues.
A couple of issues may happening. Firstly, you need to have php5-fpm installed (FastCGI Process Manager). I was trying to run it with my standard version of PHP but it was not working - http://www.php.net/manual/en/install.fpm.php
I also had Apache installed, and even if it weren't running it must have had some conflict because once I uninstalled Apache I was able to execute the PHP files.
I would also look at this line
fastcgi_pass 127.0.0.1:9000;
And consider changing it to
fastcgi_pass unix:/var/run/php5-fpm.sock;
Here is a detailed guide to installation of Nginx and PHP5-FPM for RHEL (and other OS's)
http://www.if-not-true-then-false.com/2011/install-nginx-php-fpm-on-fedora-centos-red-hat-rhel/
Related Topics
How to Get Count of Rows in MySQL Table Using PHP
"Cannot Send Session Cache Limiter - Headers Already Sent"
What Does $$ (Dollar Dollar or Double Dollar) Mean in PHP
Sending Email Via PHP Mail Function Goes to Spam
How to Delete a Line from the File With PHP
Sum Values of Multidimensional Array by Key Without Loop
A Non Well Formed Numeric Value Encountered
Are PHP Include Paths Relative to the File or the Calling Code
How to Call Shell Script from PHP That Requires Sudo
PHP Function to Make Slug (Url String)
Send File Attachment from Form Using PHPmailer and PHP
Post Request in Laravel - Error - 419 Sorry, Your Session/ 419 Your Page Has Expired
What's the Maximum Value For an Int in PHP
How to Define a Class Property Value Dynamically in PHP