Table of Contents
Laravel Valet is a lightweight development environment tailored for macOS that simplifies local PHP development. With its seamless setup and minimal configuration, it’s a perfect choice for developers seeking speed and efficiency. Valet enhances productivity by handling even complex components, like calendars, allowing you to focus on creating robust applications.
In this blog, we’ll explore how to install and set up Laravel Valet. We’ll also learn how Laravel development experts customize Valet configuration to their needs. Plus, we’ll dive into troubleshooting common issues that you can face while using Laravel Valet. With that said, let’s dive in!
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 is a powerful and efficient local development environment specifically designed for Mac users. It offers a streamlined and hassle-free way to set up and manage PHP development projects. Here’s why you should consider using it:
- Minimal Setup: Valet requires minimal configuration, making it incredibly easy to get started.
- Rapid Performance: It leverages Nginx for lightning-fast performance, significantly reducing load times.
- Intuitive Domain Management: Valet allows you to assign custom .test domains to your projects, simplifying site management and organization.
- Seamless Switching: Quickly switch between different projects by accessing their respective .test domains in your browser.
- Easy Switching: Valet enables you to effortlessly switch between different PHP versions, ensuring compatibility with various project requirements.
- Simplified Workflow: No need to install multiple PHP versions manually; Valet handles the process efficiently.
- Public Access: With a single command, you can share your local sites publicly, facilitating collaboration and testing.
- Secure Sharing: Valet employs secure tunneling to protect your development environment while sharing your sites.
- Minimal Resource Usage: Valet consumes minimal system resources, making it ideal for developers with limited hardware.
- Optimized Performance: Its efficient design ensures optimal performance, even on less powerful machines.
Laravel Valet is a compelling choice for developers seeking a fast, efficient, and user-friendly local development environment. 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?
Laravel Valet simplifies the process of running multiple PHP projects simultaneously, thanks to its use of tools like nginx and dnsmasq. Before diving into the installation process, ensure that you have Homebrew and Composer already installed on your macOS system.
Step 1: Install Homebrew
Homebrew is a package manager for macOS that makes it easy to install and manage software. If you don’t have Homebrew installed, run the following command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
This will download and install Homebrew on your system.
Step 2: Install PHP (Valet requires PHP 7.4+)
Valet relies on PHP to run your projects. To install the required version of PHP (7.4 or higher), execute:
brew install php
This will install the latest stable version of PHP on your system.
Step 3: Install Composer
Composer is a dependency manager for PHP, and it’s required to install Laravel Valet. To install Composer, run:
brew install composer
Once installed, you can verify Composer’s installation by typing composer in your terminal.
Step 4: Install Laravel Valet
With Homebrew, PHP, and Composer ready, you can now install Laravel Valet. Run the following Composer command to install Valet globally:
composer global require laravel/valet
Make sure that ~/.composer/vendor/bin is included in your system’s PATH. This is essential for running Valet commands from anywhere in your terminal.
Step 5: Run Valet Install
The final step is to configure Valet. To do this, simply run:
valet install
This command sets up and configures essential services like nginx and dnsmasq, enabling Valet to serve your local projects. After running this, Laravel Valet will be up and running, ready for local PHP development.
With these steps, you will have Laravel Valet installed and fully functional on your system. You can now enjoy a streamlined and fast local development environment!
Looking to build a robust website using Laravel?
Setting Up Projects with Valet
Once Laravel Valet is installed and running, linking your projects to Valet is straightforward. This section will guide you through setting up individual projects and serving multiple projects within a directory.
Link a Single Project
To serve a specific project with Laravel Valet, navigate to your project directory and run the following commands:
cd ~/Sites/my-laravel-project
valet link
This creates a symbolic link for the project, making it accessible via a custom local domain, such as my-laravel-project.test. Open your browser and enter this URL to access your project.
Serve Multiple Projects in a Directory
If you have multiple projects in a single directory and want to serve all of them simultaneously, you can “park” the directory with Valet. To do this, navigate to the parent directory containing your projects:
cd ~/Sites
Then, run the following command to park the directory:
valet park
Now, all the projects inside the ~/Sites directory will be available via URLs like project-folder-name.test. For example, if you have a project named blog inside the ~/Sites directory, you can access it at blog.test in your browser.
Laravel Valet makes it seamless to switch between projects by serving each one through its unique .test domain. Whether you’re working on a single project or managing a directory full of applications, Valet ensures a hassle-free local development experience.
Customizing Valet Configuration
Laravel Valet offers flexibility to adapt its configuration to your specific development needs. Whether you want to change the default top-level domain (TLD) or secure your sites with HTTPS, Valet provides easy commands to make these adjustments. Here is how you can make these two configurations:
Change the Top-Level Domain (TLD)
By default, Laravel Valet uses .test as the top-level domain for serving your projects. You can customize this to another TLD, such as .dev, using the following command:
valet tld dev
After running this command, all your Valet-served sites will now be accessible via the .dev domain (e.g., my-laravel-project.dev). This is useful if you prefer a different TLD for personal or team workflows.
Secure Sites with HTTPS
Valet allows you to enable HTTPS for your local projects easily. To secure a specific project, use the following command:
valet secure my-laravel-project
This generates and applies a local SSL certificate, ensuring your project is served over HTTPS. For example, after running the command, your project will be accessible at https://my-laravel-project.test.
Revert Secure Settings
If you decide to remove HTTPS for a project later, you can revert the changes with the following command:
valet unsecure my-laravel-project
This switches the project back to using HTTP.
By following these steps, you can easily adjust Laravel Valet to suit your workflow and enjoy a more personalized local PHP development environment. If you are looking to build a customized website that aligns with your needs, consider getting in touch with our Laravel development company.
Troubleshooting Common Issues
While Laravel Valet is designed to streamline local PHP development, you might encounter occasional issues. Here’s a step-by-step guide to resolving two common problems: the “Site Not Found” error and PHP version mismatches.
Resolving the “Site Not Found” Error
If you try to access a project and see a “Site Not Found” error, the issue might be due to an incorrect project setup. Follow these steps to troubleshoot:
Step 1: Verify if your project is linked or parked:
valet links
Step 2: If the project isn’t linked or parked, navigate to the project directory and run:
valet link
Or
valet park
Test the .test domain in your browser again to confirm it resolves correctly.
Fixing PHP Version Mismatch
Laravel Valet uses the globally installed PHP version, which might not align with your project requirements. To resolve a PHP version mismatch:
Step 1: Install the desired PHP version (e.g., PHP 8.1) using Homebrew:
brew install php@8.1
Step 2: Unlink the current PHP version and link the desired version:
brew unlink php && brew link php@8.1
Step 3: Restart Laravel Valet to apply the changes:
valet restart
After this, Valet will use the newly linked PHP version.
Quick Tips for Smooth Valet Operations
- Always ensure that dnsmasq is configured correctly, as it manages domain resolutions for Valet.
- Use valet logs to review the nginx logs for specific error details.
By following these steps, you can quickly resolve common Laravel Valet issues and maintain a seamless local development experience.
Need expert assistance with your Laravel project?
FAQs on Laravel Valet
To Summarize
Laravel Valet makes local PHP development on macOS incredibly efficient and hassle-free. Its lightweight design, quick setup, and seamless project management allow developers to focus on building applications rather than dealing with complex configurations.
Using Laravel Valet you can link individual projects and also serve multiple directories. Additionally, Valet allows you to customize settings like TLDs and HTTPS which offers flexibility to choose the security level.
If you are looking to build a robust website efficiently and effectively, hire Laravel developers.