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 phpfpm or nginx works fine but I think nginx isn't aware of phpfm 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.

  • Can you post your configuration files? – Lekensteyn Apr 10 '11 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. – Ashish Kumar - Ashfame Apr 10 '11 at 21:50

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_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /home/ashfame/www/domain.in/public_html$fastcgi_script_name;
  • +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 '13 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? – Manish Sapkal Oct 30 '15 at 12:10


  • 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.
  • yes, I have reloaded nginx and tried Force refresh too but still I can't figure out what's going wrong here – Ashish Kumar - Ashfame Apr 10 '11 at 19:38
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 '/'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.