Yii 2 Framework Configure on Plesk 17 – Nginx

Hi,
today i want to explain how to configure a app with framework Yii 2 on your hosting Plesk.
In my case i have Plesk 17.8, the problem is how to configure the subdirectory and so how to convert the htaccess of Yii 2 app.

On Plesk 17 you must to configure the site, on run PHP-FPM un on nginx.
So go in the Hosting Setting of the domain:

Hosting Setting

So go in the Hosting Setting of the domain:

Apache & nginx Settings

You must to disable Proxy mode

Than we must to configure the Additional nginx directives
So go in the Apache & nginx Settings of the domain
Than into Additional nginx directives copy this code (change YOURDOMAIN with the domain that you want to configure):

set $base_root /var/www/vhosts/YOURDOMAIN/httpdocs;

charset UTF-8;
index index.php index.html;

location / {
	root $base_root/frontend/web;
	try_files $uri $uri/ /frontend/web/index.php$is_args$args;

	location ~ ^/assets/.+\.php(/|$) {
		deny all;
	}
}

location /admin {
	alias $base_root/backend/web/;

	# prevent the directory redirect to the URL with a trailing slash
	location = /admin {
		# if your location is "/backend", try use "/backend/backend/web/index.php$is_args$args"
		# bug ticket: https://trac.nginx.org/nginx/ticket/97
		try_files $uri /backend/web/index.php$is_args$args;
	}

	try_files $uri $uri/ /backend/web/index.php$is_args$args;

	location ~ ^/admin/assets/.+\.php(/|$) {
		deny all;
	}
}

location ~ ^/.+\.php(/|$) {
	rewrite (?!^/((frontend|backend)/web|admin))^ /frontend/web$uri break;
	rewrite (?!^/backend/web)^/admin(/.+)$ /backend/web$1 break;

	fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
	fastcgi_param PATH_INFO $fastcgi_path_info;
	fastcgi_pass "unix:///var/www/vhosts/system/YOURDOMAIN/php-fpm.sock";
	include /etc/nginx/fastcgi.conf;
}

location ~ /\. {
	deny all;
}

If you want you can enable nginx caching

Press “OK” and enjoy