0

This baffled me big time. When I visit the domain, it download the index.php file. When I visit domain/index.php, it's working fine. I have tried to comment here and there, just can't fix it. This one is Zend Framework 3. I have other php site on the same server. They are fine. I start to wonder it's ZF3 special now.

My nginx is like this:

server {
  listen       80;
  server_name  xxx.xxx.com;
  index index.php index.html;
  root         /data/www/xxx/public;

  location ~ \.php$ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include       fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME /data/www/xxx/public/index.php; 
  }

  access_log logs/worth.jusfeel.cn.log main;
}

I have tried other settings as well. It's the same. The url in the addressbar change to ..domain/index.php , but still download the index.php file.

server {
  listen      80;
  server_name www.example.com;
  root        /var/www/www.example.com/myapplication;
  index       index.html index.htm index.php;

  location / {
    try_files $uri $uri/ /index.php$is_args$args;
  }

  location ~ \.php$ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
  }
}
Hao
  • 6,291
  • 9
  • 39
  • 88

1 Answers1

0

Downloading the index.php file means that nginx doesn't using php-fpm to process file. Most common reason behind this situation is misconfiguration between nginx and php-fpm.

Checklist:

  1. Make sure that you didn't disabled the cgi.fix_pathinfo directive in php.ini. It provides real PATH_INFO/PATH_TRANSLATED support for CGI and it is enabled (1) by default.
  2. Make sure that root of your virtual host points to public directory of your ZF3 application. In this case you may need to replace it from /var/www/www.example.com/myapplication to /var/www/www.example.com/myapplication/public
  3. Most important part is you need a proper fastcgi_split_path_info directive in location ~ \.php$ { } block since all PHP requests processed through index.php. This directive defines a regular expression that captures a value for the nginx $fastcgi_path_info variable.

For example:

location ~ \.php$ {
  fastcgi_pass            127.0.0.1:9000;
  fastcgi_split_path_info ^(.+.php)(/.+)$;
  fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include                 fastcgi_params;
}

Hope it helps.

edigu
  • 9,878
  • 5
  • 57
  • 80