DEV Community

Aniebiet Aaron
Aniebiet Aaron

Posted on

Mastering Development Environments with Valet: A macOS Guide

Title: Mastering Development Environments with Valet: A macOS Guide

Valet on macOS

Introduction

As a developer, setting up a local development environment can be a daunting task. Configuring servers, managing databases, and handling domain names often involve a steep learning curve. However, there's a tool that can simplify this process for macOS users – Laravel Valet. In this article, we will explore how to use Valet to streamline your development environment setup and make your life as a developer easier.

What is Laravel Valet?

Laravel Valet is a development environment tool specifically designed for macOS. It provides a simple and lightweight way to run local web applications using a variety of web servers such as Nginx and Caddy, along with integrated services like MySQL, PostgreSQL, and Redis. Valet also handles domain name resolution automatically, allowing you to access your projects with user-friendly URLs.

Getting Started

Before diving into Valet, make sure you have the following prerequisites:

  1. Homebrew: A package manager for macOS.
  2. Composer: A dependency manager for PHP.
  3. PHP: Install a supported version (7.2+ recommended) via Homebrew or any other method.
  4. Valet: Install Valet using Composer.

Once you have these prerequisites in place, you're ready to start using Valet.

Setting Up Valet

  1. Install Valet: Run the following command to install Valet globally via Composer:
   composer global require laravel/valet
Enter fullscreen mode Exit fullscreen mode
  1. Park Your Domain: Navigate to the directory where you store your projects and run:
   valet park
Enter fullscreen mode Exit fullscreen mode

This command tells Valet to start serving your projects from this directory.

  1. Start Valet: To start Valet and its underlying services, simply run:
   valet start
Enter fullscreen mode Exit fullscreen mode

Valet will automatically start Nginx and dnsmasq to handle web server and domain name resolution.

Creating a New Project

Now that Valet is up and running, let's create a new web project using Valet:

  1. Create a Project Directory: Create a new directory for your project and navigate into it using the terminal.

  2. Install Your Framework or CMS: Depending on your choice of framework or content management system (e.g., Laravel, WordPress, or plain HTML/CSS), install it in this directory.

  3. Link Your Project: Once your project is set up, link it to Valet with the following command:

   valet link project-name
Enter fullscreen mode Exit fullscreen mode

Replace project-name with a unique name for your project. Valet will automatically configure a domain for your project, such as http://project-name.test.

Accessing Your Project

With your project linked to Valet, accessing it is as simple as opening a web browser:

  • Open your web browser.
  • Enter your project's URL, e.g., http://project-name.test.

Valet takes care of routing the request to the correct project directory, making it effortless to work on multiple projects simultaneously.

Additional Features

Valet offers several advanced features:

  1. Database Management: Valet includes support for various databases like MySQL, PostgreSQL, and Redis. You can easily configure and manage these services for your projects.

  2. Secure Sites: Use valet secure to enable HTTPS for your projects, providing a secure development environment.

  3. Sharing Your Local Environment: With valet share, you can share your local development environment with others, allowing them to access your projects temporarily.

Conclusion

Laravel Valet simplifies the process of setting up a local development environment on macOS. With its user-friendly commands and automated domain name resolution, you can focus on coding without worrying about server configurations. Whether you're building web applications, websites, or testing APIs, Valet is a valuable tool that can significantly boost your productivity as a developer. Give it a try and experience the joy of hassle-free local development on macOS. Happy coding!

Top comments (0)