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:

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
htaccess, didinit, and so on - Alexey Shimansky