Hi Everyone,
I thought I’d write this How To because this issue took me 1 day to resolve and there weren’t very good tutorials out there. This is regards to the Yii2-Advance Template.
The Folder Structure
--App
-
- Common
- Backend
- Web
- Frontend
- Web
What we’re going to do is point Frontend > Web to www.mysite.com
and
Backend Web to admin.mysite.com
This is the best solution without messing around with the .htaccess. It’s a lot cleaner and using what Apache Virtual host is about.
-
Go to Cpanel and create a virtual host for www.mysite.com either via 1) Add-on Domain or 2) Create Sub-cpanel account
-
www.mysite.com will now be pointing to your --app folder, you want it to point to /frontend/web
Now login to your server via SSH root access and start navigating to /usr/local/apache/conf
You’ll see the file
vi httpd.conf
Inside you’ll see Virtual Host configurations Like
# Ensure that Apache listens on port 80
Listen 80
<VirtualHost *:80>
DocumentRoot "/www/mysite"
ServerName www.mysite.com
# Other directives here
</VirtualHost>
- Here is the tricky part. Do not edit this file. This file is automatically generated by cpanel so if you edit it, cpanel will override it once it restarts and wipe out your changers.
What you want to do is write a ‘hook’ that inserts itself into the code. You do this by creating a separate file in
/usr/local/apache/conf/userdata/std/2_2/$user/$domain/$includename.conf
just use the vi command to create the file.
User is the name of the cpanel user and domain is the domain name you want to modify.
Include name is any name you want to call it. Above is for a stand not ssl virtual host.
Then make the path change
DocumentRoot "/www/mysite[u]/frontend/web[/u]"
-
Now you restart your apache server from cpanel.
-
Now for the admin.mysite.com. You simple create a subdomain using the cpanel and point it to /backend/web, this is less difficult.
I hope you guys find this useful.