I have setup an nginx server with php5-fpm. When I try to load the site I get a blank page with no errors. Html pages are served fine but not php. I tried turning on display_errors in php.ini but no luck. php5-fpm.log is not producing any errors and neither is nginx.
nginx.conf
server {
listen 80;
root /home/mike/www/606club;
index index.php index.html;
server_name mikeglaz.com www.mikeglaz.com;
error_log /var/log/nginx/error.log;
location ~ \.php$ {
#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
here's my nginx error log:
2013/03/15 03:52:55 [error] 1020#0: *55 open() "/home/mike/www/606club/robots.txt" failed (2: No such file or directory), client: 199.30.20.40, server: mikeglaz.com, request: "GET /robots.txt HTTP/1.1", host: "mikeglaz.com"
I wrote a short C program that returns the environment variables passed from nginx to the fastCGI application.
Save this to a file, e.g.
fcgi_debug.c
To compile it, first install
gcc
andlibfcgi-dev
, then run:To run it, install
spawn-fcgi
, then run:Then, change your nginx fcgi config to point to the debug program:
Restart nginx, refresh the page, and you should see all the parameters appear in your browser for you to debug! :-)
The reason this problem occurs is because the fastcgi configurations in nginx do not function as required and in place or processing, they respond as html data. There are two possible ways in which you can configure your nginx to avoid this problem.
Method 1:
Method 2:
Both the methods would work properly, you can go ahead and take any one of them. They almost perform the same operations with a very few difference.
This solved my issue:
These hints helped me with my Ubuntu 14.04 LTS install,
In addition I needed to turn on the
short_open_tag
in/etc/php5/fpm/php.ini
In case anyone is having this issue but none of the above answers solve their problems, I was having this same issue and had the hardest time tracking it down since my config files were correct, my ngnix and php-fpm jobs were running fine, and there were no errors coming through any error logs.
Dumb mistake but I never checked the Short Open Tag variable in my php.ini file which was set to
short_open_tag = Off
. Since my php files were using<?
instead of<?php
, the pages were showing up blank. Short Open Tag should have been set toOn
in my case.Hope this helps someone.
This is my vhost for UBUNTU 18.04+apache+php7.2
The last line makes it different than the other answers.