1

I am setting up a VPS and followed the nginx, PHP, MySQL instructions for WordPress from this tutorial http://tutspundit.com/howto-install-nginx-php-fpm-mysql-php533-wordpress-ubuntu-part-1/ and then http://tutspundit.com/how-to-install-nginx-php-fpm-mysql-php533-wordpress-part-2/

The problem is the php file returns the php code itself in the browser without parsing it. So what did I miss?

Update: Staring php-fpm or nginx works fine. I think nginx isn't aware of php-fpm at all, some link is missing perhaps? I checked nginx error logs but there is nothing related to PHP. I can't seem to figure out what is missing.

2
  • Can you post your configuration files?
    – Lekensteyn
    Apr 10, 2011 at 20:58
  • @lekensteyn thanks! turns out to be a silly mistake, I was testing PHP on a xxx.xx.xxx.xxx/index.php and didn't edit the default config file.
    – Ashfame
    Apr 10, 2011 at 21:50

3 Answers 3

4

Turns out to be a silly mistake of not editing the default config file to proxy PHP request.

server {
    listen   80;
    server_name domain.in;
    access_log /home/ashfame/www/domain.in/logs/access.log;
    error_log /home/ashfame/www/domain.in/logs/error.log;

    location / {
        root   /home/ashfame/www/domain.in/public_html;
        index  index.html index.php;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /home/ashfame/www/domain.in/public_html$fastcgi_script_name;
    }
}
2
  • 1
    +1 note that if you are using virtual hosts, this php block seems to need to go inside the individual files (not in the defaults file)
    – kfmfe04
    May 12, 2013 at 5:46
  • hello @ashfame, I have similar problem. I have tried same as you told. Here I have posted my question stackoverflow.com/questions/33409539/…. Can you please guide me, where to look? Oct 30, 2015 at 12:10
0

Checks:

  • Have you reloaded nginx after changing the configuration? You can do that with sudo service nginx reload.
  • Nginx sets headers which cause the browser to cache pages. Make sure you're not seeing the cached version of the PHP page by pressing Ctrl + F5 (Firefox). Alternatively, use curl or wget to verify that the problem is not caused by your browser. You'd better to follow the official sources on installing php-fpm on nginx.
1
  • yes, I have reloaded nginx and tried Force refresh too but still I can't figure out what's going wrong here
    – Ashfame
    Apr 10, 2011 at 19:38
0
location ~ [^/]\.php(/|$) {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

this will parse all all .php files in the URI, plus paths starting or ending with '/'.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .