Pada postingan yang terdahulu tentang instal yii menggunakan composer, kita dapatkan bahwa url frontend yii adalah http://localhost/smandja/frontend/web dan url backend yii adalah http://localhost/smandja/backend/web>
Kita bisa membuat url tersebut menjadi lebih singkat dan unik dengan menggunakan virtual host. Sehingga kita tidak terlalu direpotkan dengan mengetikan url yang lumayan panjang.
Pertama, kita buat dulu file configurasinya. Ketikan perintah berikut
sudo nano /etc/apache2/sites-available/yiiadv.conf
Isinya file tersebut dengan perintah berikut ini :
[html]<VirtualHost *:80>
ServerName yii-frontend.local
DocumentRoot /var/www/html/smandja/frontend/web
<Directory /var/www/html/smandja/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
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName yii-backend.local
DocumentRoot /var/www/html/smandja/backend/web
<Directory /var/www/html/smandja/backend/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
</Directory>
</VirtualHost>
[/html]
Aktifkan virtual hostnya
sudo a2ensite yiiadv.conf
Restart service
sudo service apache2 restart
Edit file /etc/hosts
sudo nano /etc/hosts
Tambahkan
127.0.0.1 yii-frontend.local yii-backend.local
Sekarang akses http://yii-frontend.local