Yii2 - getting 404 Error after installing Yii/Nginx

Hi communitiy

I’ve installed Nginx, php-fpm and MariaDB by this tutorial but I chose PHP version 7 instead of 5.

After this I copied the web app to /var/www/default/. First I got some DB errors which I resolved. Now I’m getting a 404 Not Found error on the site I want to open. localhost is forwarding to localhost/site/login which throws the 404. I tried localhost?r=site/login and it is also forwarding to /site/login.

Here some informations:

PHP 7.0.27

Nginx 1.13.9

Maria DB 10.2.13

Yii 2.0

/usr/local/etc/nignx/sites-available/default




server {

listen 80;

server_name localhost;

root /var/www/default/app;


access_log /usr/local/etc/nginx/logs/default.access.log main;


set $yii_bootstrap "index.php";


location / {

    index  index.html $yii_bootstrap;

    try_files $uri $uri/ /index.php$request_uri;

}


location ~ \.php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}


location = /info {

allow 127.0.0.1;

deny all;

rewrite (.*) /.info.php;

}


# phpmyadmin

location ~ ^/phpmyadmin/(.+\.php)$ {

try_files $uri =404;

fastcgi_intercept_errors on;

root /usr/local/share/;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}


error_page 404 /404.html;

error_page 403 /403.html;

}



Any suggestions to solve this error?

here’s the link to the tutorial:

Try change




location / {

    index  index.html $yii_bootstrap;

    try_files $uri $uri/ /index.php$request_uri;

}



To:





location / {

    index  index.html $yii_bootstrap;

    try_files $uri $uri/ /web/index.php$request_uri;

}



Thx for your answer.

I changed these 4 lines and the 404 error is still there.

Any other suggestions? In my opinion, the url resolving doesn’t work correctly.

root should point to the web directory of the Yii application, not the base directory.

This is correct. So if you changed it, revert these.