Yii Is Making Me Sad

I wanted to learn YII.

But For 2 days i’m trying to setup nginx (+ubuntu +php-fpm) for yii. Unsuccessfully of course - every configs for nginx, even these founded on yiiframework.com FAILS (booom!). Throwing errors or just not working properly with demo app.

Can somebody help me, paste WORKING config for nginx or should i visit fuelphp website?

What exactly fails? Where are your errors? Do simple php scripts work? Is there a routing problem?

This is my nginx.conf:





user _www;

worker_processes  1;


events {

	worker_connections  1024;

}


http {

	include					mime.types;

	default_type			application/octet-stream;


	client_max_body_size	100M;


	sendfile        on;

	keepalive_timeout  65;


	gzip  on;


	server {

		listen   	80;

		server_name  localhost;

		autoindex	on;

		index 		index.html index.htm index.php;


		charset utf-8;


		location / {

			root   /usr/local/var/www;

			index  index.html index.htm index.php;

		}


		location ~ \.php$ {

			fastcgi_pass   127.0.0.1:9000;

			fastcgi_index  index.php;

			fastcgi_read_timeout 3600;

			include        fastcgi_params;

			fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

		}


		location ~ /\.ht {

			deny  all;

		}


		include vhosts/*.conf;

	}

}



And this is a sample vhost.conf in vhosts/*.conf:




location /www/project {

    try_files $uri $uri/ /www/project/index.php?$args;

}



[size="2"]Everytime I create a new yii/wordpress project with nice urls, all i have to do is copy this 3 lines to a new file and reload nginx. Works with ubuntu and mac os x and php-fpm 5.3 - 5.5[/size]

Well, it’s nginx making you sad, not Yii.

I’m using the following (with latest stable nginx built from sources):

nginx.conf




worker_processes 1;


error_log  logs/error.log  warn;

pid        logs/nginx.pid;


events {

    worker_connections  1024;

}


http {

    server_names_hash_bucket_size 64;


    include       mime.types;

    default_type  application/octet-stream;


    sendfile        on;

    keepalive_timeout  65;


    gzip  on;

    charset utf-8;

	

    index index.php index.htm index.html;

	

    include vhosts/*.conf;

}



vhosts/yii2.conf (you can create as many .conf files as you want there, it will read all these)




server {

	listen       80;

	server_name  yii2-basic.local;

	root	/dev/yii2-basic-dev/web/;


	location / {

		try_files   $uri $uri/ /index.php?$args; # Redirect everything that isn't real file to index.php including arguments.

	}


	location ~ \.php$ {

		include fastcgi.conf;

		fastcgi_pass   127.0.0.1:9000;

	}


	location ~ /\.(ht|svn) {

		deny all;

	}

}



fastcgi.conf




fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

fastcgi_param  QUERY_STRING       $query_string;

fastcgi_param  REQUEST_METHOD     $request_method;

fastcgi_param  CONTENT_TYPE       $content_type;

fastcgi_param  CONTENT_LENGTH     $content_length;


fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

fastcgi_param  REQUEST_URI        $request_uri;

fastcgi_param  DOCUMENT_URI       $document_uri;

fastcgi_param  DOCUMENT_ROOT      $document_root;

fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  HTTPS              $https if_not_empty;


fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;

fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;


fastcgi_param  REMOTE_ADDR        $remote_addr;

fastcgi_param  REMOTE_PORT        $remote_port;

fastcgi_param  SERVER_ADDR        $server_addr;

fastcgi_param  SERVER_PORT        $server_port;

fastcgi_param  SERVER_NAME        $server_name;


# PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param  REDIRECT_STATUS    200;



If nginx is making you sad, try the Hiawatha web server. Success guaranteed! :rolleyes:

P.S.

This forum doesn’t allow me to include a link in my post. Just google for Hiawatha web server. You’ll find it.