Never dealt with the yii2 framework. I downloaded the entire site on ftp + base to it.

Files dropped in /var/www/html - but it did not work.
When switching to localhost/index.php - exhaust errors.
Connection to the database did seem to be correct.
Are there any nuances when porting a site to yii2 to a local machine?
Exhaust

 //exit(); //Main config file with all settings and autoloads require_once "config/autoload.php"; //Set 1 to see the work time and sql queries $debug = new Debug(0); //Main object of site also contains all modules objects $mv = new Builder(); $products_delete = isset($_SESSION['shop']['cart']) && $_SESSION['shop']['cart'] ? $_SESSION['shop']['cart'] : ""; if ($products_delete && is_array($products_delete)) { $products_delete = $mv -> products -> select(array("id->in" => implode(",",array_keys($products_delete)))); $mv -> cart -> deleteProducts($products_delete); } //Router refers to include needed view to display the page include_once $mv -> router -> defineRoute(); //If 1 was passed above, displays the data $debug -> displayInfo($mv -> router); 
  • So what kind of mistakes? - Invision
  • In addition to the description of the error, it would be better described in detail step by step what they did. Where did they download, set up htaccess , did init , and so on - Alexey Shimansky
  • Exhaust indicated, but I do not think that it will help. Moreover, this exhaust was before I put the base. - votanko
  • There's also a web root folder. Did you write everything correctly? - Urmuz Tagizade
  • in yii web root folder ?? or something I do not understand? - votanko

2 answers 2

To begin with, you should read the documentation on how to configure a virtual host in Linux. Any virtual host. And only after that try to try on frameworks, etc.))

I'll try to describe under Ubuntu 14.04 how to do it.

  • Run here: http://www.yiiframework.com/download/#yii2 download Yii 2 with basic application template - this is the basic template with the vendor folder (the framework itself)
  • Go to the folder /var/www create a directory, for example yii2-app and throw everything into it in the downloaded folder yii-basic-app-2.0.7/basic . As a result, in the folder /var/www/yii2-app must be the folder assets, config, vendor, web, etc.

  • Go to /etc/apache2/apache2.conf and add (if there are no such lines):

     ServerName localhost ## Для того, чтобы Apache интерпретировал php и не предлагал сохранить php-файл AddType application/x-httpd-php .php .phtml ## Установка кодировки UTF-8 по умолчанию AddDefaultCharset UTF-8 # 
  • Go to /etc/apache2/sites-available/ create the configuration file yii2-app.conf , write to it what is under the spoiler:

 <VirtualHost *:80> ServerName yii2-app ServerAdmin webmaster@localhost DocumentRoot /var/www/yii2-app <Directory /var/www/yii2-app> Options Indexes FollowSymlinks AllowOverride All Require all granted </Directory> ErrorLog /var/www/yii2-app/logs/error.log CustomLog /var/www/yii2-app/logs/access.log combined </VirtualHost> 

  • Create a packs logs in the folder /var/www/yii2-app and the files error.log and access.log
  • Now we need to enable the sites-enabled site .... for this we simply create a sim link of the config from sites-available .... To do this, you can write in the terminal: ln -s откуда_копируем куда_копируем . In our case it is:

     sudo ln -s /etc/apache2/sites-available/yii2-app.conf /etc/apache2/sites-enabled/yii2-app.conf 
  • Open the file /etc/hosts , register

     127.0.0.1 localhost 127.0.0.1 yii2-app 
  • Open the terminal, enable the mod rewrite apache and restart it:

     sudo a2enmod rewrite sudo service apache2 restart 

At a minimum, folders should appear at http://yii2-app . If not, then you need to configure the rights of the folders. It is very dangerous, but you can run chmod 777 /var/www/yii2-app -R in the console, which allows you to read and write and execute all the files for everyone. So you can not do! Though you will see your folders. It's just to demonstrate that everything has appeared and you just need to adjust the permissions for the folders.

  • In /var/www/yii2-app/config/web.php you must set a value for the cookieValidationKey key

And at least at http://yii2-app/web , you’ll already see something:

enter image description here

In general, you need more. .htaccess

One .htaccess in the root /var/www/yii2-app with settings: Options + FollowSymlinks RewriteEngine On

 <IfModule mod_rewrite.c> RewriteCond %{REQUEST_URI} ^/.* RewriteRule ^(.*)$ web/$1 [L] RewriteCond %{REQUEST_URI} !^/web/ RewriteCond %{REQUEST_FILENAME} !-f [OR] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ web/index.php </IfModule> 

And one .htaccess in the /var/www/yii2-app/web folder with the contents:

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php 

And the rest is set up in the configuration files ... It should work

  • sudo a2enmod rewrite - after this command the Apache stopped rising. [mpm_prefork: notice] [pid 2812] AH00163: Apache / 2.4.10 (Ubuntu) configured - resuming normal operations [mpm_prefork: notice] [pid 2812] AH00169: caught SIGTERM, shutting down - votanko
  • But no - I am a ram, thank you very much for the initial guide. He really helped me. - votanko

In Yii2, the root folder is web.
And you have a root site / var / www / html . Change to / var / www / html / web

The example cited for the Basic application. But the essence does not change.

  • nothing has changed, but thanks for the info - I'll know. - votanko
  • let's solve the problem. Throw off the screen error please. - Urmuz Tagizade