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

Published February 8th, 2022
2 minute read
Warning!
This was written over two years ago, so some information might be outdated. Frameworks and best practices change. The web moves fast! You may need to adjust a few things if you follow this article word for word.

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

1brew update
1brew update

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

1brew upgrade php
1brew 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:

1composer global update
1composer global update

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

1valet use php --force
1valet 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

1brew upgrade redis
1brew upgrade redis

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

1pecl install redis
2valet restart
1pecl install redis
2valet 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.

Want Updates?

Sign up here if you want to stay in the loop about new articles or products I'm making.
I'll never spam you. Unsubscribe at any time.
Copyright ©2024 Austen Cameron