Dmitri DB Dmitri DB - 1 year ago 53
PHP Question

Yii site served by nginx or apache only serves main page

EDIT ONE: I've also tested this on Windows 7 with apache, and there the exact same thing happens. This means that the problem is primarily the routing of all pages to the home page.

EDIT TWO: As per a suggestion in the #yii IRC channel, I replaced the contents of the .htaccess file with a much-simplified one from a working project. This hasn't yielded any change in the problem, however.

EDIT THREE: I've got this working just fine now with some changes to my code. Answer below

I've been trying to import a site written with the Yii Framework that I've imported to my workstation. I'm encountering a problem where trying to load any page does nothing but direct to the main page. This means all requests are essentially routed exactly as if I loaded the root request. No errors pop up in the access log or error log; the requests look like the following in nginx's access log, where 'example' is either 'localhost', '', or the server's IP address:

Accessing root ( http://example/ ): - - [08/May/2013:13:05:28 -0700]
"GET / HTTP/1.1" 200 8436 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0"

Accessing login ( http://example/site/login ): - - [08/May/2013:13:07:01 -0700]
"GET /site/login HTTP/1.1" 200 8427 "http://example/" "Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0"

Accessing the same controller by http://example/index.php?r=site/login: - - [08/May/2013:14:40:45 -0700]
"GET /index.php?r=site/login HTTP/1.1" 200 8419 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0"

Considering I've got 2 other Yii projects set up which work fine, which are using a server configuration similar to which I'll also paste below, I'm thinking that it may be something in the workings of the application itself that I'm not keen to yet. If anyone has any suggestions for anything else I could share, try out, or compare to in the working projects I've imported from other sites, it'd be greatly appreciated :)

edit: switched in config closer to what I had actually been using. This is probably irrelevant considering the project has the same problem while running in Apache on Windows.

server {
server_name localhost;
listen 80;
keepalive_timeout 70;

root /usr/www/[project name omitted]/public_html;

client_max_body_size 4M;
client_body_buffer_size 4M;
client_header_buffer_size 4M;

location / {
try_files $uri $uri/ /index.php?$args;
autoindex on;

location ^~ /data/ {
expires 30d;

# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;

#Disable logging for favicon
location = /favicon.ico {
log_not_found off;
access_log off;

#Disable logging for robots.txt
location = /robots.txt {
allow all;
log_not_found off;
access_log off;

location ~ /themes/\w+/views {
deny all;
access_log off;
log_not_found off;

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
try_files $uri =404;
#fastcgi_intercept_errors on;
#fastcgi_connect_timeout 20;
fastcgi_send_timeout 20;
fastcgi_read_timeout 600; # For xdebug to work alright
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;


I've got everything sorted out after contacting the original developer of this project, who has informed me of a few changes that needed to be made. They are as follows:

  • Updating instances of code that looks like this:

    $_SESSION['allowdownload'] = true;
  • With this:

    $session=new CHttpSession;
    $session['allowdownload'] = true;
  • As well as changing the setting in protected/config/main.php for 'showScriptName' in the urlManager array to 'true' rather than 'false'. I hope that this helps someone else out at some point!