D
D
Doniyor Mamatkulov2017-10-04 20:26:32
Yii
Doniyor Mamatkulov, 2017-10-04 20:26:32

How to set up Yii2 for shared hosting?

Hello!
I'm trying to upload a ready site on Yii2 to virtual hosting.
Everything works fine on the locale, but from the hosting it gives out the page "Apache 2 Test Page powered by CentOS
" +Indexes - does not help! 3. There is an entry in the error log. I do not have access to the httpd.conf config. So far, returned .htaccess in root to this form:

Directory index forbidden by Options directive

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

RewriteCond %{REQUEST_URI} !^/(web)
RewriteRule ^assets/(.*)$ /web/assets/$1 [L]
RewriteRule ^css/(.*)$ web/css/$1 [L]
RewriteRule ^js/(.*)$ web/js/$1 [L]
RewriteRule ^images/(.*)$ web/images/$1 [L]
RewriteRule ^fonts/(.*)$ web/fonts/$1 [L]
RewriteRule ^sitemap.xml web/sitemap.xml [L]
RewriteRule ^robots.txt web/robots.txt [L]
RewriteRule (.*) /web/$1

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

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-10-04
@slo_nik

Good evening.
If there were no index page, then most likely you would get a 403 error or yii2 would fail.
The problem, I think, is in the .htaccess and urlManager settings.
Try to do the following:
1) In the root of the project, put .htaccess with the following content

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine on
</IfModule>

<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>

2) In the web directory such .htaccess
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

And check the website.
After these manipulations, the web directory should leave the address bar. Additional parameters for connecting resources do not need to be written in .htaccess, add all resources to the web and configure AssetBundle.
If the project is located in your subdirectory, then specify the following parameter in the configuration file
'request' => [
   'baseUrl' => '/name_folder', // перед именем должен быть слеш
],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question