Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am setting up a VPS and followed the nginx, PHP, MySQL instructions for WordPress from this tutorial and then

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.

share|improve this question
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 and didn't edit the default config file. – Ashfame Apr 10 '11 at 21:50
up vote 3 down vote accepted

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

server {
    listen   80;
    access_log /home/ashfame/www/;
    error_log /home/ashfame/www/;

    location / {
        root   /home/ashfame/www/;
        index  index.html index.php;

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /home/ashfame/www/$fastcgi_script_name;
share|improve this answer
+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…. 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.
share|improve this answer
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 '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 '/'.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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