How do i install a specific version of php on mac?

Change language:

Submit a Pull Request Report a Bug

Table of Contents

  • Using Packages
  • Using the bundled PHP prior to macOS Monterey
  • Compiling PHP on macOS

This section contains notes and hints specific to installing PHP on macOS. PHP is bundled with macOS since macOS X (10.0.0) prior to macOS Monterey (12.0.0). Compiling is similar to the Unix installation guide.

+add a note

User Contributed Notes

There are no user contributed notes for this page.

I love the speed at which PHP is moving these days and how fast the new versions are, too 🙂 but that doesn’t mean the software on which we’re going is going to consistently be able to keep up with the fast release cycles.

And that’s okay. It is part of software development and it has been since before most of us were writing our first lines of code (let alone before we were even alive). Obviously, this means that those of us who work with PHP are likely going to need to work with different versions.

Sometimes we’ll be working with the latest, sometimes we’ll working with a version or a few versions older, and sometimes we may need to work with something that’s deprecated.

And this is usually the part where certain engineers start saying we should upgrade all the things and stay with the newest version of languages and frameworks. But that’s not how it works.

What does this have to do with PHP, though?


Assume for a moment that you’re working on a project that was written with 8.0 but you start rolling it out to a suite of products. Some are running on a server with 7.4, some are running 7.3, and some are running 7.2.

Is it easier to handle all of the other software already running on their servers or refactoring your code?

A bit of a rhetorical question.

I’ve written before about my affinity for using Homebrew to install the software on my machine. This is no different for PHP.

However at the time of this writing, I versions of PHP available via brew.sh are as follows:

  • ✅ 8.0.18
  • ⚠️ 7.4.29
  • 🚫 7.3.33
  • 🚫 7.2.34
How do i install a specific version of php on mac?

And the latter two are deprecated. The problem with this is that if you try to install any of the deprecated versions, then Brew won’t allow you to do it.

So if you need a deprecated version of PHP but Brew won’t let you install it, what are we supposed to do?

Install an Old Version of PHP

In short:

  1. Tap a repository that includes it,
  2. Install it via that repository.

I’ll do into detail about the terminology at the end of the article but here’s how I ended up installing PHP 7.2.34 on my machine.

How do i install a specific version of php on mac?

First, I found a repository that was maintaining older versions of PHP. I found this repository here.


📝 Note: If you ever worry about a particular repository being deleted, fork it into your local repository and then set it up so you can tap it later. The gist of that is another article, though.


Next, I issue the following command in my terminal:

~ brew tap shivammathur/php

Then I installed PHP 7.2:

~ brew install shivammathur/

And I updated my .zshrc file and sourced it in the terminal so it runs the recently installed version:

export PATH="/opt/homebrew/opt//bin:$PATH"
export PATH="/opt/homebrew/opt//sbin:$PATH"

And this is how you can install old versions of PHP.

A Note on Terminology

In short tap means that we’re adding a repository outside the standard list of repositories available to Homebrew.

When you install Homebrew, a selected set packages are available but if you want to expand the set of available packages, you add repositories to Hombrew. And to do that, you do the tap command.

How do I install different versions of PHP on Mac?

Switching between multiple PHP versions on macOS.
Prerequisites. You'll need both Xcode Command Line Tools and Homebrew installed. ... .
Install Multiple PHP Versions. As of writing, only PHP 7.2, 7.3 and 7.4 are maintained and supported by Homebrew. ... .
Switching between PHP versions..

How do I install a specific version of PHP?

In short what you need to do is:.
Ensure the php packages for the version you want are installed..
Update any configuration for that PHP version..
Update your web server configuration to point to the correct PHP version..
Point PHP CLI to the correct PHP version..
Restart your web server and php-fpm..
Mask the old php-fpm daemon..

How do I upgrade PHP to 7.4 on Mac?

6 Answers.
brew install [email protected]..
brew link --force --overwrite [email protected]..
brew services start [email protected]..
export PATH="/usr/local/opt/[email protected]/bin:$PATH".
export PATH="/usr/local/opt/[email protected]/sbin:$PATH".

How do I install PHP on my Mac?

Install PHP on macOS Monterey.
brew --version..
brew install php..
command -v php..
/usr/local/bin/php..
/opt/homebrew/bin/php..
#!/usr/bin/env php..
b) You can include inline scripts in expansions. A simple inline script in PHP would be: {/PHP. echo "Hello"; }.