Laravel Valet is a lightweight development environment for macOS that simplifies the process of setting up and managing local PHP projects. It's designed for developers who prefer a minimalist approach and want to get their projects up and running quickly. In this post, we'll explore how to use Valet and showcase some practical examples.
Getting Started with Laravel Valet
First, let's install Valet using Composer:
composer global require laravel/valet
valet installThis will set up Valet on your system, including Nginx and DnsMasq.
Key Features and Examples
Serving Sites
Valet makes it incredibly easy to serve your Laravel projects. Simply navigate to your project directory and run:
valet parkNow, your project is accessible at http://projectname.test.
Secure Sites
To serve your site over HTTPS, use:
valet secure projectnameSharing Sites
Valet allows you to easily share your local sites with others:
valet shareThis generates a public URL that you can share with anyone.
Custom Domains
You can link a specific project to a custom domain:
valet link custom-domainNow your project is accessible at http://custom-domain.test.
Suggested Usages
Rapid Prototyping: Quickly set up new Laravel projects for experimentation.
laravel new myproject cd myproject valet linkMulti-framework Development: Valet supports various PHP frameworks. Use it to manage multiple projects:
valet park ~/Sites/laravel valet park ~/Sites/symfonyDatabase Management: Use Valet with tools like DBngin for easy database setup:
valet use [email protected] valet db create myprojectTesting Email Templates: Use Valet with MailHog to test email templates locally:
valet composer require laravel/homestead-valet-driver valet use mailhogAPI Development: Use Valet for local API development and testing:
Route::get('/api/users', function () { return User::all(); });
Access this API at http://myproject.test/api/users.
Best Practices
Use PHP Versions: Easily switch between PHP versions:
valet use [email protected]Customize Nginx Configurations: Create site-specific Nginx configurations in
~/.config/valet/Nginx/.Regular Updates: Keep Valet updated:
composer global update valet installLeverage Custom Drivers: Extend Valet's functionality with custom drivers for specific project requirements.
Laravel Valet offers a streamlined, resource-efficient way to manage local PHP development environments. Its simplicity and flexibility make it an excellent choice for developers who want to focus on coding rather than configuration. Whether you're working on a single Laravel project or juggling multiple PHP frameworks, Valet provides the tools to make your local development process smooth and efficient.
Remember, while Valet is powerful for local development, always ensure your production environment is properly configured and secured. Happy coding with Laravel Valet!
