Upgrading to PHP 8 for Laravel 9 with Valet and Homebrew on Mac OS

Published February 8th, 2022
2 minute read

Today is the official release day for Laravel 9. This release is packed full of goodies. Unfortunately, I've been a slacker about upgrading to PHP 8. If you're like me and still on PHP 7.4, here's how you can upgrade.

Updating PHP to 8.x

First, make sure homebrew's information is up-to-date

brew update

Next, tell homebrew to update PHP (this took a while to run)

brew upgrade php

Next we need to upgrade Laravel Valet and make sure it is using PHP 8.

Hopefully you can now run php -v and get 8.x as a result. If not, you may need to uninstall PHP and run brew install php

Updating Laravel Valet

Update Valet and its dependencies with Composer:

composer global update

Finally, we need to tell Valet to use our new PHP version. Run the following command:

valet use php --force

This forces valet to unlink (and re-link) the PHP version.

Bonus: Upgrading Redis

I often use Redis for queues, so I chose to upgrade that too.

First use Homebrew to upgrade Redis

brew upgrade redis

Last step is using PECL to install the Redis extension in PHP. Then restart Valet and you're all set!

pecl install redis
valet restart

You should now be running on PHP 8. Enjoy!

Enjoy this article? Follow me on Twitter for more tips, articles and links.
😢 Awww, nobody has liked or mentioned this on Twitter yet.

Join the Newsletter ❤️

A most excellent monthly newsletter with code & design tips, curated links and more!
Don't worry, I'll never send you spam. Unsubscribe at any time.