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.
Old Versions of PHP With Homebrew
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
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
- Tap a repository that includes it,
- 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.
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 firstname.lastname@example.org
And I updated my
.zshrc file and sourced it in the terminal so it runs the recently installed version:
And this is how you can install old versions of PHP.
A Note on Terminology
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