One of the challenges with building solutions on WordPress is working with the various environments each host provides.
That is, some are still running very old versions of PHP; others are running newer versions, but even then there are variations among them.
Case in point: I’ve been running PHP 7.2 on my local machine for development for some time; however, I’m currently on a project where a few of the dependencies on the continuous integration tool offers support only for PHP 7.1.
And because I like my development environment to mirror the staging and production environments, I think it’s important to make sure there’s parity.
Multiple Versions of PHP with Homebrew
First, you want to make sure that you have PHP 7.1 installed. To do this, you simply run the following command in your terminal. This will install the package but nothing more. You’ll still be running whatever version of PHP you’re currently running.
$ brew install email@example.com
After that, you’ll need to tell Homebrew to remove the symbolic link that it’s created to the current version of PHP you’re running and then link it to the package that you’ve just downloaded.
To do that, enter the following command:
$ brew unlink php && brew link --force firstname.lastname@example.org
Remember all that talk about shells? You’ll need to make sure that your shell – in this case, Bash – is aware of the version of PHP you want to use.
export PATH="/email@example.com/bin:$PATH" export PATH="/firstname.lastname@example.org/sbin:$PATH"
Next, list out all of the services that brew is running. You can do this by entering the following command:
$ brew services list
Once you do this, you’re going to see a list of the services that are running as well as the account under which some of them are running.
If some are running as root then you’re going to need to start and stop them using sudo; otherwise, you can stop and start them using your standard commands.
$ sudo brew services stop php $ sudo brew services stop email@example.com $ sudo brew services start firstname.lastname@example.org
$ valet restart