How to set up Laravel Valet (Nginx) + MySQL

A Few months ago, Tabacitu assigned me a task to install & try Spatie's Browsershot on the Laravel Valet environment. It was the fi...

Karan Datwani
Karan Datwani

A Few months ago, Tabacitu assigned me a task to install & try Spatie's Browsershot on the Laravel Valet environment. It was the first time I heard of Laravel's valet. I installed it on my Mac M1 and tested a few local sites. I'm amazed by the experience it delivers.

Valet runs nginx in the background and uses DnsMasq to proxy all requests on the *.test domain to point to sites installed on your local machine. You can use it for many popular frameworks like Zend, CakePHP 3, Magento, Drupal, Joomla, WordPress, Static HTML etc. If you need to support multiple PHP versions across various sites - the steps are here.

Why choose Valet?

I have seen many beginners using XAMPP or MAMP on their system, but struggling for faster response. I was one of them. Why do beginners use XAMPP or MAMP? Because it's difficult to set up nginx and virtual host in the beginning. But using Valet... the setup part is a smooth experience. It's just one command!

Steps to install Valet

In order to install Laravel Valet you'll need: Mac OS & Homebrew. To install Laravel Valet:

  1. Make sure you have Homebrew installed - if you don't have it, you can install it by running this command in your terminal:
/bin/bash -c "$(curl -fsSL"
  1. Install PHP and Composer - you can do this by running these commands in your terminal:
brew install php
brew install composer
  1. Install Valet with Composer:
composer global require laravel/valet
  1. After installation, you can run the valet install command in your terminal to install Valet. This will configure and install Valet on your system.
  2. Once Valet is installed, you can use it to serve your Laravel applications by navigating to your project's root directory and running the valet link command. This will register the directory with Valet, and you can access it by visiting http://directory-name.test in your browser.

That's it! You should now have Laravel Valet up and running on your system.

How to install MySQL

  1. To install MySQL and phpMyAdmin on your system, you can follow these steps:
brew install mysql
  1. Once the installation is complete, start the MySQL server by running:
brew services start mysql
  1. Secure your MySQL installation, setup a root password by running:
sudo mysql_secure_installation

How to install PHPMyAdmin

Now, in order to see the tables and entries in those databases, you'll need a database client. You can choose to install a Mac-only app like SequelAce or TablePlus... or, what I prefer to do is to install good old PhpMyAdmin, who has been around for years and served me very well:

  1. To install phpMyAdmin run:
brew install phpmyadmin
  1. Get installed phpmyadmin folder path and the config file path by running:
brew info phpmyadmin
  1. Go to the phpmyadmin folder and run valet link. This will register phpmyadmin directory with Valet and you can access it by visiting http://phpmyadmin.test in your browser.

Note: If you are not using any password for MySQL user, you have to update the config file param$cfg['Servers'][$i]['AllowNoPassword'] to true

Alternative SQL clients

If you don't like PHPmyadmin, that's ok. For example, not all Backpack team members use it. Here are some of the alternatives each one of us uses:

  • TablePlus (used by @promatik and @maurohmartinez)
  • SequelAce (@tabacitu's favourite)


Laravel Valet is an easy-to-install and efficient development environment for macOS. It allows developers to run multiple sites on their local machine without the need for complicated configuration. With the power of Nginx and DnsMasq, Valet provides fast and reliable responses.

By following the simple steps, you can easily set up a local PHP server environment and start building your application.

Want to receive more articles like this?

Subscribe to our "Article Digest". We'll send you a list of the new articles, every week, month or quarter - your choice.

Reactions & Comments

What do you think about this?

PHP Monitor for Valet is also a nice tool to have on hand 🫡
Yes @Andrei3, It has really good compatibility with the valet. Thanks for the info.✌️

Latest Articles

Wondering what our community has been up to?