Skip to main content
Logo
Overview
Installing Laravel Valet on MacOS

Installing Laravel Valet on MacOS

June 4, 2024
4 min read

Laravel Valet is a powerful development environment for MacOS that allows you to easily serve your Laravel sites. It configures your Mac to always run Nginx in the background when your machine starts, providing a blazing fast Laravel development experience. In this guide, we’ll walk through the steps to install Valet on your MacOS machine.

1. Install Xcode

Install Xcode via the command line:

Terminal window
xcode-select --install

Or via the Apple Store

Alternatively, you can install it via the Apple Store. For more information, refer to the documentation.

2. Generate and add an SSH Key

An SSH key is a secure way to authenticate with servers and services without having to provide your password each time. Here’s how to generate and add an SSH key:

Step-by-step:

Terminal window
ssh-keygen -t ed25519 -C "your_email@example.com"
pbcopy < ~/.ssh/id_ed25519.pub
touch ~/.ssh/config
nano ~/.ssh/config

Paste the following into the terminal:

Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519

In nano, save the file with ctrl + o, then ctrl + x and enter to exit. Then, run:

Terminal window
eval "$(ssh-agent -s)"
ssh-add --apple-use-keychain ~/.ssh/id_ed25519

For more information, see GitHub’s guide on generating SSH keys.

3. Install Homebrew

Homebrew is a package manager for MacOS that makes it easy to install various Unix tools and open-source software. Install it with the following command:

Terminal window
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then, set up your shell to use Homebrew. Read the brew docs.

Terminal window
touch ~/.zprofile
nano ~/.zprofile

Paste the following into the file, replacing “yourprofile” with your actual username:

Terminal window
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/yourprofile/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
zsh

Brew will tell you exactly what commands need echoed in your zshell.

Exit nano and run:

Terminal window
zsh

Verify the installation with:

Terminal window
brew doctor

4. Installing PHP

Installing PHP via Homebrew: PHP 7.4 is deprecated, we will need to install a brew tap: shivammathur/php

Terminal window
brew tap shivammathur/php
brew install php@7.4

All the additional versions of PHP can be installed, so you can switch them as needed. The commands below is a handy way to see what versions are available:

Terminal window
brew search php
brew install php@8.2
brew install php

Verify your PHP installation with:

Terminal window
php -v

5. Installing Composer (PHP Dependency Manager)

Terminal window
curl -sS https://getcomposer.org/installer | php
mkdir -p /usr/local/bin
sudo mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer
which composer

The last command should output:

/usr/local/bin/composer

6. Installing Laravel Valet

Terminal window
composer global require laravel/valet
valet install
mkdir valet && cd valet
valet park

If successful, you should see this output: “This directory has been added to Valet’s paths.”

Now we can add an unzipped WordPress install to that directory, and rename it to the TLD we want to use. For example, if we want to use the domain example.test, we would add the WordPress install to the valet directory, and rename it to example.

A domain extension of .test will be added to the end automatically. So, if you want to use example.test, you would name the directory example.

7. MariaDB Server

Our SQL DB isn’t installed, so let’s do that next.

Terminal window
brew install mariadb

Starting the server:

Terminal window
brew services start mariadb

Initial setup and securing the installation:

Terminal window
mysql_secure_installation

Verifying the installation: Connect using

Terminal window
mysql

With that command it will prompt you for your password, and you can use these commands to create databases and users:

create database DATABASE_NAME;
grant all privileges on DATABASE_NAME.* TO 'USER_NAME'@'localhost' identified by 'PASSWORD';
flush privileges;
exit;

8. NVM and Node.js

Node.js is a JavaScript runtime used for serving assets. NVM (Node Version Manager) allows you to easily install and switch between Node versions.

Installing NVM:

Terminal window
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash

Replace v0.39.4 with the latest version from the NVM GitHub repository.

Verifying the installation:

Terminal window
command -v nvm

Installing Different Versions of Node.js Using NVM

Installation command:

Terminal window
nvm install --lts
nvm install 14.16.0 # for a specific version

Switching between versions:

Terminal window
nvm use <version>

Setting a default version:

Terminal window
nvm alias default <version>

Verifying the installation:

Terminal window
node -v

9. Using Oh My ZSH

Oh My Zsh is a framework for managing your Zsh configuration that provides helpful functions, aliases, and themes for your command line.

Read the docs here.

Terminal window
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

To edit your terminal theme, edit the .zshrc file in your home directory.

ZSH_THEME="xiong-chiamiov-plus"

Oh My Zsh has many other plugins and configuration options to streamline your command line workflow. Check out their documentation to learn more.

Wrapping Up

You now have a fully functioning Laravel Valet development environment on your Mac! Place your Laravel projects in the ~/valet directory and they will be instantly accessible at https://projectname.test. For further customization options, check out the official Laravel Valet documentation.

Some additional configuration you may want to set up includes:

  • Installing additional PHP extensions
  • Configuring a preferred code editor
  • Setting up additional Valet drivers for other frameworks

Happy coding!