Update PHP to version 8 in macOS using Homebrew

Haytam Bakouane
2 min readAug 4, 2021

--

Check out my blog for more articles like this: https://hbakouane.dev/blog

Updating PHP in a macOS machine can be difficult, you cannot just install Xampp, MAMP, or WAMP, run it, and then you have PHP 8 in your machine, you have to go through some steps that we will be showing in this article.

If you want to upgrade to a version between 5.3 and 7.3

If so, there is an easy solution called “PHP for OS X”, which doesn’t support any version higher than PHP 7.3.

to profit from this solution: https://php-osx.liip.ch/

Upgrading to PHP 8

First things first, we have to install PHP on our machine

// Install PHP 8
// This will install the latest PHP version
brew install php
// To install a specific version, run this command:
brew install php@8.0

Now if we check the current PHP version, we will still see 7.1 or another one, which means we have to make the system consider PHP 8 as the default version, to do that we have to run this command:

brew link --force php@8.0

Restart the services:

brew services start php@8.0

we still cannot see PHP 8.0 when we run

php -v or php --version

2 commands are left to make this work:

export PATH="/usr/local/opt/php@8.0/bin:$PATH"
export PATH="/usr/local/opt/php@8.0/sbin:$PATH"

And voila, we have successfully installed PHP 8.0 on our machine

php -v
// Output:
PHP 8.0.9 (cli) (built: Aug 2 2021 22:56:15) ( NTS )
Copyright (c) The PHP GroupZend Engine v4.0.9, Copyright (c) Zend Technologieswith Zend OPcache v8.0.9, Copyright (c), by Zend Technologies

I passed 3 days trying to solve this and upgrade PHP from 7.1 to 8.0 in a 2011 MacBook, no results and suddenly I ran into this answer in StackOverflow which helped me a lot and I said why not share it with others!

I hope this helped.

Check out my blog for more articles like this: https://hbakouane.dev/blog

Read More:

Integration of Laravel + VueJs + AdminLTE made easy

Models Pruning in Laravel 8.50.0 explained

5 Javascript libraries that will help you build your stunning Portfolio

A Laravel SaaS Boilerplate to start working on your next project

--

--

Haytam Bakouane

It's Haytam here, I work with Laravel/Vue, I seek to learn new things daily as possibly as I could, Now I'm learning Tailwind, such a great framework!