Skip to content
Advertisement

PHP CLI on Apple M1 using Homebrew

I’ve followed this guide to install Homebrew on an M1 based Mac.

After that I ran

brew install php@7.4

which installed PHP successfully.

If I now run

brew upgrade php

I get

Error: php not installed

What I like to achieve is to update the PHP that comes shipped with macOS, which is 7.3.22 when I run php -v.

How can I update PHP using Homebrew? I understood that I need to put something in my PATH to point to the newer PHP version? Given this is a new machine I actually don’t have a .bash_profile file, only a .zshrc (I’m using ZSH, I assume that this file will be used and that I don’t need a .bash_profile?)

Advertisement

Answer

It’s not advisable to upgrade the system-provided PHP, but it’s also not necessary.

brew link can be used to decide which PHP is utilized. brew link php@7.4 should do the trick; this can be also used to switch PHP versions around, i.e. brew link php@8.0 will switch you over to that while leaving both versions installed and available directly.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement