Setting Up Development Domains with Laravel Valet

Feb 13, 2025

Setting Up Development Domains with Laravel Valet

Introduction

Setting up a local development environment is crucial for efficient web development. Laravel Valet provides a lightweight and flexible solution for managing local development domains on macOS. This guide walks you through installing Valet, setting up development domains, and configuring proxies for your projects.

1. Install Composer

First, ensure you have Composer installed, as Laravel Valet requires it. Run the following command:

brew install composer

2. Install Laravel Valet

Valet is a minimalistic development environment for macOS that uses Nginx and Dnsmasq to manage local domains.

2.1 Install PHP

Before installing Valet, ensure PHP is installed:

brew install php

2.2 Install Valet via Composer

Next, install Valet globally using Composer:

composer global require laravel/valet

Once installed, run the Valet installation command:

valet install

This command sets up Valet and configures Dnsmasq for local domain resolution.

3. Setup Development Domains

To define a custom top-level domain (TLD) for your local projects, use:

valet domain dev

This sets up *.dev domains to resolve to your local machine.

4. Configure Proxies

If you need to proxy requests to a running local service (such as a frontend app running on port 3000), use the valet proxy command:

valet proxy yoursite.pl http://127.0.0.1:3000 --securevalet proxy yoursite.com http://127.0.0.1:3000 --securevalet proxy yoursite.rs http://127.0.0.1:3000 --securevalet proxy yoursite.sk http://127.0.0.1:3000 --securevalet proxy yoursite.cz http://127.0.0.1:3000 --securevalet proxy yoursite.nl http://127.0.0.1:3000 --securevalet proxy yoursite.de http://127.0.0.1:3000 --securevalet proxy yoursite.co.uk.dev http://127.0.0.1:3000 --secure

The --secure flag ensures that each domain runs over HTTPS.

5. Configure Dnsmasq

To ensure your custom domains resolve correctly, edit the Dnsmasq configuration file located at:

~/.config/valet/dnsmasq.d/tld-dev.conf

Add the following entries:

address=/.sk.dev/127.0.0.1address=/.cz.dev/127.0.0.1address=/.pl.dev/127.0.0.1address=/.com.dev/127.0.0.1address=/.rs.dev/127.0.0.1address=/.co.uk.dev/127.0.0.1address=/.nl.dev/127.0.0.1address=/.eu.dev/127.0.0.1address=/.de.dev/127.0.0.1listen-address=127.0.0.1

This ensures that requests to these domains correctly resolve to 127.0.0.1.

6. Test Your Setup

Now, you can access your project in the browser using:

https://www.yoursite.cz.dev/

Replace yoursite with the appropriate domain from your setup.

Bonus: Setting Up Development Domains on CircleCI

If you are running automated tests in CircleCI, you may need to configure Dnsmasq for development domains. Add the following steps to your CircleCI configuration file:

....- &install_dnsmasq  run:    name: Install dnsmasq    command: |      sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 32EE5355A6BC6E42      sudo apt-get update      sudo apt-get install -y dnsmasq- &configure_dnsmasq  run:    name: Configure dnsmasq    command: |      sudo cp /etc/resolv.conf /etc/resolv.conf.backup      echo "nameserver 127.0.0.1" | sudo tee /etc/resolv.conf      cat /etc/resolv.conf.backup | sudo tee -a /etc/resolv.conf      echo "address=/yoursite.cz.dev/127.0.0.1" | sudo tee /etc/dnsmasq.d/yoursite.conf      echo "address=/www.yoursite.cz.dev/127.0.0.1" | sudo tee -a /etc/dnsmasq.d/yoursite.conf      echo "address=/yoursite.sk.dev/127.0.0.1" | sudo tee -a /etc/dnsmasq.d/yoursite.conf      echo "address=/www.yoursite.sk.dev/127.0.0.1" | sudo tee -a /etc/dnsmasq.d/yoursite.conf      echo "address=/yoursite.pl.dev/127.0.0.1" | sudo tee -a /etc/dnsmasq.d/yoursite.conf      echo "address=/www.yoursite.pl.dev/127.0.0.1" | sudo tee -a /etc/dnsmasq.d/yoursite.conf      echo "address=/yoursite.com.dev/127.0.0.1" | sudo tee -a /etc/dnsmasq.d/yoursite.conf      sudo service dnsmasq restart....'Test E2E - Cypress Invoicing':  <<: *build  resource_class: medium+  parallelism: 1  steps:    - checkout    - attach_workspace:        at: ~/yoursite-rails    - *install_dnsmasq    - *configure_dnsmasq    - setup_and_start_rails    - restore_cache: *restore_cypress_cache....

This setup ensures your CI pipeline correctly resolves development domains in CircleCI.

Conclusion

Laravel Valet provides a streamlined way to manage local development environments. By following this guide, you can set up custom local domains, configure proxies, and ensure proper domain resolution for a seamless development experience.