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:
xcode-select --installOr 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:
ssh-keygen -t ed25519 -C "your_email@example.com"pbcopy < ~/.ssh/id_ed25519.pubtouch ~/.ssh/confignano ~/.ssh/configPaste the following into the terminal:
Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_ed25519In nano, save the file with ctrl + o, then ctrl + x and enter to exit. Then, run:
eval "$(ssh-agent -s)"ssh-add --apple-use-keychain ~/.ssh/id_ed25519For 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:
/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.
touch ~/.zprofilenano ~/.zprofilePaste the following into the file, replacing “yourprofile” with your actual username:
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/yourprofile/.zprofileeval "$(/opt/homebrew/bin/brew shellenv)"zshBrew will tell you exactly what commands need echoed in your zshell.
Exit nano and run:
zshVerify the installation with:
brew doctor4. Installing PHP
Installing PHP via Homebrew: PHP 7.4 is deprecated, we will need to install a brew tap: shivammathur/php
brew tap shivammathur/php
brew install php@7.4All 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:
brew search phpbrew install php@8.2brew install phpVerify your PHP installation with:
php -v5. Installing Composer (PHP Dependency Manager)
curl -sS https://getcomposer.org/installer | phpmkdir -p /usr/local/binsudo mv composer.phar /usr/local/bin/composerchmod +x /usr/local/bin/composerwhich composerThe last command should output:
/usr/local/bin/composer6. Installing Laravel Valet
composer global require laravel/valetvalet installmkdir valet && cd valetvalet parkIf 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.
brew install mariadbStarting the server:
brew services start mariadbInitial setup and securing the installation:
mysql_secure_installationVerifying the installation: Connect using
mysqlWith 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:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bashReplace v0.39.4 with the latest version from the NVM GitHub repository.
Verifying the installation:
command -v nvmInstalling Different Versions of Node.js Using NVM
Installation command:
nvm install --ltsnvm install 14.16.0 # for a specific versionSwitching between versions:
nvm use <version>Setting a default version:
nvm alias default <version>Verifying the installation:
node -v9. 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.
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!