Php file downloading instead of executing nginx
I am installing a website in a droplet (Digital Ocean). I have an 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 files it's just downloading it... for example... Show
Any idea?
My /etc/nginx/sites-available/default
... Other "locations" are commented on... .
Jai Chauhan 3,6623 gold badges34 silver badges55 bronze badges asked Aug 31, 2014 at 10:24
9 Try this:
I just started using Linux a week ago, so I really hope to help you with this. I am using a nano text editor to edit the files. run apt-get install nano if you don't have it. Google it to know more.
Jai Chauhan 3,6623 gold badges34 silver badges55 bronze badges answered Oct 31, 2014 at 6:05
Jack M.Jack M. 3,5184 gold badges23 silver badges36 bronze badges 15 I had similar problem which was resolved by emptying the browser cache (also worked fine with different browser). answered Jan 24, 2017 at 20:51
np8np8 23.1k10 gold badges79 silver badges89 bronze badges 7 You need to add this to /etc/nginx/sites-enabled/default to execute php files on Nginx Server:
Jai Chauhan 3,6623 gold badges34 silver badges55 bronze badges answered Feb 21, 2015 at 9:38
rootxrootx 7376 silver badges11 bronze badges 9 I see a lot of solutions above and many worked correctly for me, but I didn't understand what they were doing and was worried of just copy pasting the code, specifically, fastcgi. So here are my 2 cents,
For some, servers like Apache, there is built in support to interpret PHP and thus no need for a CGI. This digital ocean link, explains the steps to install FPM pretty well and I am not writing the steps needed to solve the issue of php files getting downloaded instead of rendering since the other answers IMHO pretty good. answered Feb 11, 2019 at 17:19
codacoda 1,9022 gold badges20 silver badges24 bronze badges 3 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 answered Mar 14, 2017 at 11:58
M ArfanM Arfan 4,1574 gold badges27 silver badges44 bronze badges 3 I had the same issue and none of the answers solved the problem. I ran:
to test the config file at /etc/nginx/sites-available/default. It gave me these errors:
So I went into the config file and on the last line there was
I uncommented, ran the test command again and it worked answered Jul 1, 2017 at 18:05
1
This workded for me. 1) MyApp file vi /etc/nginx/sites-available/myApp
PHP5 users Change
to
2) Configure cgi.fix_pathinfo Set cgi.fix_pathinfo to 0 Location: PHP5 /etc/php5/fpm/php.ini PHP7 /etc/php/7.0/fpm/php.ini 3) Restart services FPM php5 php7 NGINX
answered Aug 20, 2017 at 19:46
SlimxSlimx 851 silver badge4 bronze badges 1 For me it helped to add
answered Nov 21, 2017 at 23:35
TomegTomeg 5,3992 gold badges12 silver badges9 bronze badges
The above snippets worked for me in case of php7.2 answered Oct 13, 2019 at 4:03
Avnee.AngelAvnee.Angel 1071 gold badge3 silver badges16 bronze badges 1 If any of the proposed answers is not working, try this: 1.fix www.conf in etc/php5/fpm/pool.d:
2.fix nginx.conf in usr/local/nginx/conf:
3. fix default file in etc/nginx/site-available
4.restart nginx service
5.restart php service
6.enjoy
I am using Ubuntu 14.04
answered Aug 31, 2015 at 19:19
huuthanghuuthang 4461 gold badge4 silver badges11 bronze badges 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
Hope this helps some folks who are frustrated on a sunday afternoon (c: answered May 17, 2015 at 23:24
0 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:
default.conf:
Hope this helpful and happy coding answered Feb 11, 2017 at 7:43
SonDangSonDang 1,4191 gold badge15 silver badges20 bronze badges My solution was to add
to my custom configuration file, for example Adding to answered Jun 9, 2017 at 9:33
Kelvin LowKelvin Low 6349 silver badges22 bronze badges I my case I was not using
then reloading Nginx:
answered Aug 8, 2018 at 19:25
WaqlehWaqleh 9,3508 gold badges64 silver badges100 bronze badges 0 So this is what finally worked in my case as rewrite rules where the culprit
becomes...
Apparently without the last keyword, the request didn't get restarted, so it never hit the answered Mar 19, 2019 at 21:51
I solved my problem now with this code (change your IP):
answered Aug 31, 2019 at 6:05
AndréAndré 214 bronze badges For the record, I found that my php-fpm was not running and I fixed it with
answered Jul 23, 2019 at 15:00
IslamTahaIslamTaha 8767 silver badges15 bronze badges What worked for me with Ubuntu 16.04, and php7 was deleting this line
It stopped downloading php files after that. answered May 26, 2016 at 10:04
briankipbriankip 2,4062 gold badges22 silver badges26 bronze badges Uncomment the .php location in /etc/nginx/sites-available/default
answered Mar 16, 2017 at 9:11
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. answered Jul 10, 2017 at 13:51
Al CheAl Che 691 gold badge1 silver badge5 bronze badges check your nginx config file extension is *.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. answered Jul 18, 2017 at 8:48
IvanIvan 212 bronze badges
Then open terminal and run the following command:
Then add the following code in the
If any mismatch just correction and restart Nginx from terminal by the following command
Then go to browser and Enjoy ... answered Aug 8, 2017 at 8:56
SanaullaSanaulla 1,10911 silver badges11 bronze badges For me it was the line: fastcgi_pass unix:/var/run/php5-fpm.sock; which had to be just: fastcgi_pass unix:/run/php5-fpm.sock; answered May 26, 2018 at 14:18
I was about to go mental trying to fix this, for me the issue was that Cloudflare had cached the php file and kept making me download it. The fix for me was to purge the cache on Cloudflare. answered Feb 4, 2019 at 2:23
1 I had been having the same problem what solved it was this server block also have this block above other location blocks if you have css not loading issues. Which I added to my sites-available conf file.
answered Mar 1, 2019 at 9:51
One more thing to check: if you've set up HTTPS access before setting up PHP -- I used certbot -- you'll need to make the changes in /etc/nginx/sites-available/default twice because there will be two server blocks (one listening on port 80 and one listening on port 443). (I was setting up this server primarily for email and didn't have any use for PHP when I first installed nginx just as a way to run certbot more easily.) answered Jul 11, 2020 at 20:19
I was struggling with the issue for long time, and these steps worked for me. Step 1: Location block config for all PHP files
Step 2: Add the fastcgi_param in the config file We just have to open the /etc/nginx/fastcgi_params file and add the below line at the end of the file.
And then restart the services,
answered Apr 17, 2021 at 13:47
I installed PHP with homebrew on Mac, in my case php-fpm service was not running.
Started the service and php scripts begin to execute.
My fastcgi settings in nginx server location block
answered Sep 19, 2021 at 19:46
AamirRAamirR 10.9k4 gold badges52 silver badges69 bronze badges Emptying the browser cache worked for me. answered Mar 29 at 13:18
1 Why is my PHP file downloading instead of running?This is normally due to an improper handler code. In the . htaccess file, you will want to ensure the handler code matches your version of php. If it does not, the php files may try to download instead of process.
Can Nginx serve PHP files?Create a PHP page in Nginx
After the restart, PHP is fully enabled on Nginx. To prove this, create a PHP file in Nginx's /var/www/html folder and test to ensure the page renders properly on the server. This creates the most basic PHP file outside of a “Hello World” example you could create.
How connect PHP to nginx?Connecting NGINX to PHP FPM
If you're using unix socket change fastcgi_pass to: fastcgi_pass unix:/var/run/php-fpm. sock; Restart NGINX.
How do I download from Nginx server?Here are the steps to force download file in NGINX.. Open NGINX configuration file. Open terminal and run the following command to open NGINX configuration file. ... . Force download file in NGINX. ... . Restart NGINX Server.. |