Laravel Valet Documentation

repository·master·Indexed 25 days ago

https://github.com/laravel/valet

A lightweight macOS development environment for serving local PHP sites using Nginx and DnsMasq with a *.test domain pattern. It features low resource usage, support for multiple PHP versions (php@7.1 through php@8.5), TLS certificate management, and the ability to share local sites publicly via tunnels like ngrok, expose, or cloudflared. Includes tools for managing parked paths, symbolic links, Nginx proxies, and custom Valet drivers.

Tokens
14.8K
Snippets
6
Records
128
Agent score
82%

What's inside Laravel Valet

  1. What is Laravel Valet

    master

    Laravel Valet is a minimal development environment for macOS designed for speed and low resource usage. It configures your Mac to run Nginx in the background and uses DnsMasq to proxy all requests on the *.test domain to your local sites.

    Key characteristics:

    • Minimalist: No Vagrant or manual /etc/hosts file management required.
    • High Performance: Uses approximately 7mb of RAM.
    • Public Sharing: Supports sharing local sites publicly via local tunnels.
    • Domain Pattern: Automatically serves sites using the .test TLD.
  2. Manage the Nginx service with Valet

    master

    Valet provides programmatic control over the Nginx service used to serve local sites. This includes installing the necessary configuration files, restarting the service after changes, stopping the service, or performing a forceful uninstallation.

    Note that Nginx management often requires elevated privileges (via sudo) and relies on Homebrew (brew) for service management.

  3. How the Laravel Valet driver resolves the front controller

    master
    For requests that are not identified as static files, the LaravelValetDriver resolves the request to the application's front controller. It first checks if the requested URI corresponds to an actual file within the public directory. If not, it defaults to serving {sitePath}/public/index.php.
  4. How the Nette driver identifies a site

    master

    The NetteValetDriver automatically detects and serves Nette applications. For a directory to be recognized as a Nette site by Valet, it must contain the following specific file structure:

    • www/index.php (The front controller)
    • www/.htaccess (Apache configuration)
    • config/common.neon (Nette configuration)
    • config/services.neon (Nette services configuration)
  5. How Laravel Valet handles static files and storage links

    master

    When a request is made to a Laravel site, the driver first attempts to resolve the request as a static file. It follows this priority:

    1. Public Directory: It checks if a file exists at {sitePath}/public{uri}.
    2. Storage Link: If the URI starts with /storage/, it attempts to resolve the file within the application's public storage directory at {sitePath}/storage/app/public{uri_without_storage_prefix}.

    If neither is found, it falls back to the front controller (typically public/index.php).

  6. Identify the currently linked PHP version

    master

    Valet determines which PHP version is currently active by inspecting the symlink at the Homebrew binary path (BREW_PREFIX/bin/php).

    If the PHP binary is not linked, Valet will suggest running valet use php@X.Y. The system can resolve the specific version (e.g., php@8.1) by parsing the path of the resolved symlink.

  7. How BedrockValetDriver identifies a site

    master

    Valet uses the following criteria to determine if a directory should be served using the BedrockValetDriver:

    1. The presence of the roots/bedrock-autoloader package in composer.json.
    2. The existence of the file web/app/mu-plugins/bedrock-autoloader.php.
    3. A directory structure containing web/app/, web/wp-config.php, and config/application.php.