Post

How to fix Valet after Brew upgrade

The confusing thing about Valet is that it’s installed with composer, but you use brew to install PHP.

So when you run into trouble with Valet, you often don’t know where to turn. Is the problem with homebrew or is it with Valet?

Recently, I found that after running brew update, everything fell to shit. My local websites powered by Valet no longer worked.

I was getting 502 bad gateway error. When I looked this up on the internet, I could see the error meant that Valet was confused about which version of PHP to use.

What is Laravel Valet?

Laravel Valet is a development environment for macOS that makes it easy to create and manage local development environments for PHP applications, particularly those built using the Laravel framework. It is designed to be lightweight, fast, and easy to use.

Key features of Laravel Valet include:

  1. Nginx and Dnsmasq: Valet uses Nginx as the web server and Dnsmasq to manage local DNS resolution, allowing you to access your projects using a .test domain.
  2. Automatic Site Routing: Valet automatically maps the directory name of your project to a .test domain, so you can access your Laravel project in the browser by navigating to, for example, http://myproject.test.
  3. HTTPS Support: Valet provides automatic SSL certificate creation, enabling secure HTTPS connections for your local development sites.
  4. Database Support: Valet comes with support for MySQL and PostgreSQL out of the box, making it easy to set up and manage databases for your projects.
  5. Simple CLI Commands: Valet provides a set of simple command-line tools to manage your development environment, including commands for starting, stopping, and restarting the Valet service.
  6. Tinker Integration: Laravel Valet integrates with Laravel’s Tinker REPL, allowing you to interact with your application using a command-line interface.

To get started with Laravel Valet, you typically need to install it using Composer and follow the setup instructions provided in the official documentation. It’s a popular choice among Laravel developers for creating local development environments due to its simplicity and efficiency. Keep in mind that Laravel Valet is specific to macOS environments.

How to get Laravel Valet working after brew upgrade

The answer to my problem this problem I found was on the valet Install instructions page in the setting the php version section.

1
valet use php@8.1

This function ensured Valet was using the correct version of PHP and fixed the 502 error. mywebsite is now loading.

Brew Doctor

1
brew doctor

When i run brew doctor it tells me i have some unlinked kegs - but i dont care my local website is working so i will just leave sleeping dogs lie

1
2
3
4
5
6
Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  composer
  php
  node

Brew Services List

1
brew service list

When i run the brew services list command, I see

  • php8.1 status is none and the user is root.
  • php (versionless) is also listed with a status of none an the user is actually empty (nothing listed at all).
  • Nginx and dnsmasq status is none, user is root.

Considering that brew is installs php i would think that these services would be running.

Which PHP

When i run which php i get

1
/usr/local/opt/php@8.1/bin/php
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.