Valet drivers
Valet uses drivers to handle requests. The following drivers are included:
- Laravel
- Bedrock / WordPress (Bedrock)
- CakePHP
- Concrete CMS (Concrete5)
- Contao
- Craft CMS
- Drupal
- Jigsaw
- Joomla
- Katana
- Kirby
- Magento 2
- Neos
- Radicle
- Sculpin
- Statamic (v1, v2 and current)
- Symfony
- TYPO3
- WordPress
- Static HTML / basic PHP (with or without a
public/directory)
Run valet which inside a project to see which driver serves it.
Custom Valet drivers
You can write your own driver to serve PHP applications running on a framework or CMS that is not natively supported. When you install Valet Linux+, a ~/.config/valet/Drivers directory is created containing a SampleValetDriver.php file with a sample implementation. Writing a driver only requires implementing three methods: serves, isStaticFile and frontControllerPath.
All three methods receive $sitePath, $siteName and $uri. $sitePath is the fully qualified path to the site on your machine, such as /home/lisa/sites/my-project. $siteName is the "host" / "site name" portion of the domain (my-project). $uri is the incoming request URI (/foo/bar).
Once your driver is complete, place it in ~/.config/valet/Drivers using the FrameworkValetDriver.php naming convention — for example WordPressValetDriver.php — declare it in the Valet\Drivers\Custom namespace and extend Valet\Drivers\ValetDriver.
The serves method
serves should return true if your driver should handle the incoming request, false otherwise. Within this method, determine whether $sitePath contains a project of the type you are trying to serve.
For example, a WordPressValetDriver could look like this:
/**
* Determine if the driver serves the request.
*/
public function serves(string $sitePath, string $siteName, string $uri): bool
{
return is_dir($sitePath.'/wp-admin');
}
The isStaticFile method
isStaticFile determines whether the incoming request is for a "static" file, such as an image or a stylesheet. If it is, return the fully qualified path to the file on disk; otherwise return false:
/**
* Determine if the incoming request is for a static file.
*
* @return string|false
*/
public function isStaticFile(string $sitePath, string $siteName, string $uri)
{
if (file_exists($staticFilePath = $sitePath.'/public/'.$uri)) {
return $staticFilePath;
}
return false;
}
Note
isStaticFile is only called when serves returns true for the request and the request URI is not /.
The frontControllerPath method
frontControllerPath returns the fully qualified path to your application's front controller, typically index.php:
/**
* Get the fully resolved path to the application's front controller.
*/
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
{
return $sitePath.'/public/index.php';
}
Complete example
<?php
namespace Valet\Drivers\Custom;
use Valet\Drivers\ValetDriver;
class WordPressValetDriver extends ValetDriver
{
public function serves(string $sitePath, string $siteName, string $uri): bool
{
return is_dir($sitePath.'/wp-admin');
}
public function isStaticFile(string $sitePath, string $siteName, string $uri)
{
if (file_exists($staticFilePath = $sitePath.$uri) && is_file($staticFilePath)) {
return $staticFilePath;
}
return false;
}
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
{
return $sitePath.'/index.php';
}
}
Local drivers
To define a custom driver for a single application, create a LocalValetDriver.php file in the application's root directory. It may extend the base ValetDriver class or an existing driver such as LaravelValetDriver:
<?php
use Valet\Drivers\LaravelValetDriver;
class LocalValetDriver extends LaravelValetDriver
{
/**
* Determine if the driver serves the request.
*/
public function serves(string $sitePath, string $siteName, string $uri): bool
{
return true;
}
/**
* Get the fully resolved path to the application's front controller.
*/
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
{
return $sitePath.'/public_html/index.php';
}
}
Tip
Need full control over the Nginx server block instead of the PHP-level routing? See Per-project Nginx config.