Laravel Valet: Revolutionizing Local PHP Development

Whether creating a new website or managing an old one, there are going to be several changes throughout the design, development, testing, and launch. Some will be good, and some may not work. That’s why web development services set up local development environments to build, test, and debug websites and web apps before deploying them to a production environment.

If you are using Laravel for your website or app, the Laravel Valet is a great local development environment. It works quietly in the background and offers a lightning-fast experience. Plus, you can easily share your files with your team members.

In this blog, I’ll tell you everything there is to know about Laravel Valet, along with its benefits, installation, implementation, and more. Without further ado, let’s begin.

What is Laravel Valet?

Laravel Valet is a development environment for macOS that simplifies the setup process for local Laravel development. It utilizes a native macOS feature to serve sites and share local applications globally through a secured tunnel. Additionally, it offers powerful tools for database management, SSL certification, and collaboration with team members.

This tool is highly recommended for Laravel developers in need of a user-friendly and efficient local development environment. With its streamlined setup process and elimination of complex configurations, Laravel Valet has become a popular choice among developers.

Overall, it greatly enhances the local development experience, ensuring smooth project management and execution.

Why Use Laravel Valet for Local Development?

Laravel Valet has gained popularity among developers as a preferred choice for local development environments due to several compelling reasons. Here are some key advantages that make Laravel Valet a valuable tool for local development:

  • Ease of Setup: Laravel Valet boasts a remarkably straightforward installation process. With just a few terminal commands, developers can have a fully functional local development environment up and running. This simplicity eliminates the need for extensive server configuration, saving time and effort.
  • Lightweight Footprint: Unlike more complex local development solutions, Laravel Valet maintains a lightweight footprint on your system. It efficiently utilizes resources without the need for virtual machines or containerization, resulting in a faster and more responsive development environment.
  • Seamless Laravel Integration: As the name suggests, Laravel Valet is designed to seamlessly integrate with Laravel projects. It automatically configures itself based on the specifics of a Laravel application, providing a tailored environment that aligns with Laravel’s conventions. That streamlines the development workflow effectively.
  • Automatic Site Creation: Valet simplifies the process of creating new development sites. With a single command, developers can set up a new project, complete with a local domain name, and secure HTTPS by default. This automated site creation accelerates the start of new projects and reduces the configuration overhead.
  • Support for Multiple PHP Versions: Laravel Valet supports multiple PHP versions, allowing developers to switch between different versions seamlessly. This flexibility is invaluable when working on projects that require specific PHP versions or when transitioning between different Laravel applications with varied PHP requirements.
  • Secure HTTPS Connections: Valet automatically configures secure HTTPS connections for each project, enhancing security during local development. This ensures that developers can mimic a production-like environment more closely, especially when dealing with features that rely on secure connections.
  • Efficient Handling of Subdomains: Valet simplifies the creation and management of subdomains for local projects. This feature is particularly useful for applications that utilize subdomains for various functionalities, such as multi-tenancy or distinct application sections.
  • Zero Configuration for Most Projects: For many common types of projects, Laravel Valet requires zero additional configuration. It intelligently infers the project type and sets up the environment accordingly. This “zero-config” approach contributes to a hassle-free experience for developers.

In conclusion, Laravel Valet’s simplicity, efficiency, and Laravel-specific optimizations make it an attractive choice for developers looking to enhance their local development workflow. Whether you’re a seasoned Laravel artisan or exploring PHP development services, Valet provides a user-friendly and powerful environment for building and testing web applications locally.

How to Install Laravel Valet?

Installing Laravel Valet is a straightforward process, but it’s important to note that Valet is primarily designed for macOS and Linux environments. Additionally, it relies on tools like Homebrew and Composer, so ensure these are installed on your system before proceeding. Below are the step-by-step instructions for installing Laravel Valet:

Consider the Prerequisites

Before installing Laravel Valet, you need to consider the prerequisites. That will ensure your system has the necessary dependencies in place and will pave the way for a smooth installation process.

  • Operating System: Valet is exclusively for macOS.
  • Homebrew: A package manager for macOS.
  • PHP: Valet requires PHP 7.4 or later.
  • Composer: A PHP dependency manager.

When your system has the required tools and dependencies covered, it helps create a seamless local development environment for Laravel and PHP projects.

Install Homebrew

Homebrew is a popular package manager for macOS and Linux that simplifies the process of installing, updating, and managing software packages. Here, we’ll only consider macOS.

Step 1: Open the Terminal application on your macOS. You can find it using Spotlight (Cmd + Space, then type “Terminal”) or by navigating to “Applications”> “Utilities”> “Terminal”.

Step 2: Install Xcode Command Line Tools by running the following command in the Terminal:

xcode-select --install

Step 3: Once the Xcode Command Line Tools are installed, you can proceed to install Homebrew. Paste the following command in the Terminal and press Enter:

/bin/bash -c "$(curl -fsSL"

This command initiates the installation process by downloading and running the Homebrew installation script.

Step 4: After that, follow the on-screen instructions, which typically involve pressing Enter or providing your system password when prompted.

Step 5: After the installation is complete, you can verify that Homebrew is installed correctly by running:

brew --version

This command should display the version of Homebrew installed on your system.

Homebrew will simplify the installation and management of software packages, libraries, and utilities on your system. It provides a centralized and organized way to install command-line tools and applications.

By installing Homebrew, you set the stage for a streamlined process of installing additional web development tools like the dependency manager Composer. They are prerequisites for Laravel Valet.

Install PHP and Composer

The next part of the process is installing PHP and Composer. PHP is the programming language on which Laravel is built, and Composer is a dependency manager for PHP. Here is the step-by-step guide:

Step 1: Open the Terminal application on your macOS. You can find it using Spotlight (Cmd + Space, then type “Terminal”) or by navigating to “Applications”> “Utilities”> “Terminal”.

Step 2: Run the following command in the Terminal to install PHP using Homebrew:

brew install php

This command will download and install the latest version of PHP available through Homebrew.

Step 3: After the installation is complete, you can verify that PHP is installed correctly by running:

php -v

This command should display the installed PHP version. Next is Composer download and installation.

Step 4: Composer is not available through Homebrew directly, so you need to download it separately. Visit the Composer download page and follow the instructions for your operating system.

For macOS, you can use the following commands in the Terminal:

php -r "copy('', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'baf1608c33254d00611ac1705c1d9958c817a1a33bce370c0595974b342601bd80b92a3f46067da89e3b06bff421f182') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

This script downloads and installs Composer in the current directory.

Step 5: Move the Composer executable to a directory in your system’s PATH so that you can run it from any location. For example, you can move it to /usr/local/bin/:

mv composer.phar /usr/local/bin/composer

Step 6: After moving Composer, you can verify that it is installed correctly by running:

composer --version

This command should display the installed Composer version.

Installing Composer will help you manage libraries and dependencies in your PHP projects. Laravel itself and many Laravel packages use Composer for package management.

Install Valet

This is the main part of the process. Here are detailed steps on how to install Valet:

Step 1: Open the Terminal application on your macOS. You can find it using Spotlight (Cmd + Space, then type “Terminal”) or by navigating to “Applications”> “Utilities”> “Terminal”.

Step 2: Run the following command to install Laravel Valet globally using Composer:

composer global require laravel/valet

This command downloads and installs the Valet package globally on your system.

Step 3: Add the Composer binary directory to your system’s PATH. For Bash, add the following line to your ~/.bashrc or ~/.bash_profile:

export PATH=" $PATH:$HOME/.composer/vendor/bin"

For Zsh, add this line to your ~/.zshrc:

export PATH=" $PATH:$HOME/.composer/vendor/bin"

Then, run source ~/.bashrc or source ~/.zshrc to apply the changes.

Finally, you can verify that Valet is installed correctly by running:

valet --version

This command should display the installed Valet version.

Now, all you need to do is configure Valet before using it for the local development environment. 

Configure Valet

Configuring Laravel Valet involves setting up the domain and TLD (Top-Level Domain) that Valet will use for your local development projects. This step is crucial to ensure that Valet can serve your projects under the desired domain. Here’s a detailed guide on how to configure Valet:

Step 1: When you configure the TLD, you are essentially choosing the domain extension that Valet will use for your local development projects. Common choices include “.test,” “.local,” or “.dev.” You can configure the TLD using the valet domain command.

For example, to set the default TLD to “.test,” run the following command in the Terminal:

valet domain test

This command configures Valet to use “.test” as the default TLD for serving your projects.

Step 2: While the TLD is set globally, you can also specify a custom domain for an individual project if needed. Navigate to your project’s directory in the Terminal and run the following command:

valet domain your-custom-domain

Replace “your-custom-domain” with the desired domain for that specific project.

Step 3: To verify your Valet configuration, you can run the following command:

valet tld

This command will display the currently configured TLD. Ensure that it matches the one you intended to set.

Step 4: After making configuration changes, it’s a good practice to restart Valet to apply the changes. Run the following command to restart Valet:

valet restart

This command restarts the Valet services, ensuring that the updated configuration takes effect.

Additionally, you will need to change the PHP version, configure SSL, and configure DNS. By carefully configuring Valet, you ensure that it aligns with your development needs, providing a seamless and tailored environment for your Laravel projects.

You can also hire a Laravel development company to complete this Valet installation.

How to Use Laravel Valet?

Laravel Valet is designed to be simple and intuitive, providing a streamlined local development experience for Laravel projects. Once you have installed and configured Valet, here are the key steps to use it effectively:

Step 1: Open your Terminal and navigate to the directory where you want to create the new Laravel project.

Step 2: Run the following command to create a new Laravel project (replace “project-name” with your desired project name):

composer create-project --prefer-dist laravel/laravel project-name

Step 3: Navigate into the project directory:

cd project-name

Step 4: Run this command to start Valet:

valet start

Step 5: While in your Laravel project directory, run the following command to park the directory for Valet:

valet park

This makes the project accessible at http://project-name.test.

Step 6: Open a web browser and visit http://project-name.test to see your Laravel project.

Step 7: When you’re done working on your projects, you can stop Valet:

valet stop

Step 8: Valet provides a convenient way to create MySQL databases for your projects. Run the following command to create a database for your project:

valet db create

This command will prompt you to enter the database name.

Step 9: To view the details of the MySQL database associated with your project, run:

valet db info

Step 10: If you need to interact with the MySQL console, you can use the following command:

valet db console

Valet integrates well with database management tools like Sequel Pro or TablePlus. You can connect to your project’s database using the provided credentials (usually found in the .env file) using these tools.

That concludes the process of using Laravel Valet for high-quality local development. But if you need help with it, our Laravel developers might be of assistance.

FAQs on Laravel Valet

Can I use Laravel Valet with other PHP projects besides Laravel?
Yes, Laravel Valet can be used with any PHP project. While it is specifically designed for Laravel projects, it also supports other popular PHP frameworks such as Symfony and CodeIgniter. Valet's simplicity and lightweight nature make it a great choice for any PHP development.
Can I use databases with Laravel Valet?
Yes, Valet supports both MySQL and PostgreSQL databases. To use databases with Valet, you will need to install the appropriate database server first (e.g. "brew install mysql"). Then, you can use Valet's "valet db" commands to manage your databases, such as creating new databases or importing SQL files.
How do I update Laravel Valet to the latest version?
To update Laravel Valet to the latest version, simply run the command "composer global update laravel/valet". This will update Valet to the latest version and ensure that you have all the latest features and bug fixes.

To Summarize

From creating new Laravel projects effortlessly to managing databases and navigating between PHP versions, Valet streamlines the local development process. Its ability to adapt to custom domains, coupled with the provision of secure HTTPS connections, reinforces its role as a versatile and secure tool.

Valet is an outstanding tool for productivity for Laravel experts. Its lightweight nature and close integration with Laravel conventions make it an invaluable asset for developers seeking a reliable and efficient local development environment.

If you need help with local development through Laravel Valet, contact our experts today!

Mayur Upadhyay is a tech professional with expertise in Shopify, WordPress, Drupal, Frameworks, jQuery, and more. With a proven track record in web development and eCommerce development.

Leave a comment