A Laravel Valet driver for Yii Framework applications. Supports both Yii2 and Yii3.
composer global require laravel/valetvalet installChoose one of the following drivers based on your needs:
Supports both Yii2 and Yii3 applications with automatic detection.
cd ~/.config/valet/Drivers/
wget https://raw.githubusercontent.com/chinaphp/yii2-valet-driver/master/YiiValetDriver.php -O YiiValetDriver.phpFor Yii2 applications only.
cd ~/.config/valet/Drivers/
wget https://raw.githubusercontent.com/chinaphp/yii2-valet-driver/master/Yii2ValetDriver.php -O Yii2ValetDriver.phpproject/
├── bin/
│ └── yii # Console bootstrap
├── config/
│ └── web.php # Web config
├── public/
│ └── index.php # Web entry point
├── runtime/
├── vendor/
│ └── yiisoft/yii/ # Yii3 package
└── ...
cd /path/to/yii3-project
valet link app-name# Access via browser
http://app-name.testDirectory structure
public/
index.php
api/
index.php
backend/
index.php
Access examples
http://app-name.test/
http://app-name.test/api/
http://app-name.test/backend/
cd /path/to/yii2-basic
valet link app-name# Access via browser
http://app-name.testcd backend
valet link backend-app-name
http://backend-app-name.test
cd frontend
valet link frontend-app-name
http://frontend-app-name.testcd assets
valet link assets.example
http://assets.example.test/no_image.pngcd /path/to/yii2-advanced
valet link app-name# Access via browser
http://app-name.test/api/Directory structure (works for both Yii2 and Yii3)
web/ (Yii2) or public/ (Yii3)
index.php
api/
index.php
backend/
index.php
admin/
index.php
Access examples
http://app-name.test/
http://app-name.test/api/
http://app-name.test/backend/
http://app-name.test/admin/
For project-specific configuration, use the local driver:
cp LocalValetDriver.php /path/to/your-project/LocalValetDriver.phpRun in the project root:
valet link app-nameAccess examples
http://app-name.test/
http://app-name.test/api/
http://app-name.test/backend/
Edit LocalValetDriver.php in your project root to customize:
// Change web directory priority (Yii3 first, then Yii2)
private array $webDirectories = ['public', 'web'];
// Add custom entry points
private array $entries = ['api', 'backend', 'admin', 'oauth2', 'v1', 'v2', 'custom'];The driver automatically detects the framework version based on:
| Indicator | Yii2 | Yii3 |
|---|---|---|
| Console file | /yii |
bin/yii |
| Vendor package | yiisoft/yii2 |
yiisoft/yii |
| Web directory | web/ |
public/ |
| Config file | - | config/web.php |
| Feature | Yii2ValetDriver | YiiValetDriver | LocalValetDriver |
|---|---|---|---|
| Yii2 Support | ✅ | ✅ | ✅ |
| Yii3 Support | ❌ | ✅ | ✅ |
| Auto-detection | ✅ | ✅ | ✅ |
| Asset Subdomain | ✅ | ✅ | ✅ |
| Multiple Entry Points | api, backend | api, backend, admin, oauth2, v1, v2 | Customizable |
| Static Files | ✅ | ✅ | ✅ |
| Global Installation | ✅ | ✅ | ❌ (Project-specific) |
If you're upgrading from Yii2ValetDriver to YiiValetDriver:
-
Backup your existing driver:
cp ~/.config/valet/Drivers/Yii2ValetDriver.php ~/.config/valet/Drivers/Yii2ValetDriver.php.bak
-
Install the new driver:
cd ~/.config/valet/Drivers/ wget https://raw.githubusercontent.com/chinaphp/yii2-valet-driver/master/YiiValetDriver.php -O YiiValetDriver.php
-
Restart Valet:
valet restart
-
Test your existing Yii2 projects - they should work without any changes!
Check if your project has one of:
/yiifile (Yii2) orbin/yiifile (Yii3)vendor/yiisoft/yii2(Yii2) orvendor/yiisoft/yii(Yii3)web/index.php(Yii2) orpublic/index.php(Yii3)
Ensure your web directory contains the static files. The driver looks in web/ (Yii2) or public/ (Yii3).
Use LocalValetDriver.php and customize the $entries array.
MIT