Yii2: Separate front and backend in advanced-app doesn't work on XAMPP

我的梦境 提交于 2019-12-02 07:10:29

I always use the following way when setting up a new project when I am working in the office where we have ubuntu and it always works perfectly.

Follow these steps below, and create 2 virtual hosts with the name www.myapp.com and admin.myapp.com

1) Open terminal and type

  • sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/www.myapp.com.conf.
  • sudo nano /etc/apache2/sites-available/www.myapp.com.conf.

add the following code once the file opens.

<VirtualHost *:80>
       ServerName www.myapp.com
       DocumentRoot "/path/to/project/root/frontend/web"

       <Directory "/path/to/project/root/frontend/web">
           # use mod_rewrite for pretty URL support
           RewriteEngine on
           # If a directory or a file exists, use the request directly
           RewriteCond %{REQUEST_FILENAME} !-f
           RewriteCond %{REQUEST_FILENAME} !-d
           # Otherwise forward the request to index.php
           RewriteRule . index.php

           # use index.php as index file
           DirectoryIndex index.php

           # ...other settings...
       </Directory>
</VirtualHost>

2) Close & save the file and then in terminal write

  • sudo a2ensite www.myapp.com.conf
  • open hosts file sudo nano /etc/hosts and add in the end on a new line 127.0.0.1 www.myapp.com.
  • Restart apachesudo service apache2 restart

3) Repeat the above steps for the backend and change the file names and ServerName, Directory and DirectoryRoot respectively.

4) Just make sure you have a .htaccess file in the frontend/web and backend/web with the following

RewriteEngine on

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

And thats it you wont need any other .htaccess file other than these now type in the browser www.myapp.com or admin.myapp.com and see it working.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!