Install PHP with Homebrew
This lesson assumes you are on a Mac. If you are on a Windows or Linux computer, your install process will be different.
See the official PHP docs at php.net for info on how to install PHP. Click Documentation, and English, and then you will see links for Installation and Configuration.
We’ll see docs for Linux, Mac, and Windows. This tutorial assumes you are using Mac, but if you have another O/S feel free to follow the instructions there.
PHP used to be automatically included on macOS, but Apple removed the binary from all versions of macOS starting with Monterey.
But this is no problem! I actually never much liked the built-in PHP version, because it seemed that newer versions were released, and it was always hard to switch back & forth between the older and newer versions.
Under Installation on macOS, click Using Packages.
Another tool named Homebrew makes this easy. Let’s click this link to go to brew.sh.
This is the home page for Homebrew, which is a great package manager for macOS. Homebrew will provide the ability to easily install software packages on macOS that may otherwise be a bit difficult to install, such as PHP.
Let’s install it by copying this line, then opening up Terminal and paste it in.
Be sure NOT to run this line as
root ! Brew is meant to be accessed by your local user account, so it doesn’t need those escalated privileges.
After it’s done installing, Homebrew can be referenced by a new command named “brew”.
After it installs, you can type “brew” and should see some output like this. If you see something like this without errors, it means brew is now installed.