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;
}
}
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:
php.ini
. It provides real PATH_INFO
/PATH_TRANSLATED
support for CGI and it is enabled (1)
by default.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
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.