How to set up PHP7.4 on MacOS.
This is all very well and good. Apart from one small insignificant thing…
The version of PHP in use is currently 7.4.
This means that we must install the specific version of PHP on a Mac. This is where the difficulties lie.
Setting up PHP on MacOS. I initially used the command
brew install php
This command did install PHP on my machine. Unfortunately, the command
brew install php7.4
does not install version 7.4. it actually returns a warning which can be shown below.
Warning: No available formula with the name "[email protected]". Did you mean [email protected] or [email protected]?
To correctly install PHP7.4 on a MacOS then follow the below snippets and save yourself plenty of heartache!
First, we need to add a new tap to homebrew which provides formulas for the different PHP versions including PHP 7.4 (which we need).
brew tap shivammathur/php
Second, once this tap has been added correctly. We can then install PHP7.4 which can be done using the below command.
brew install shivammathur/php/[email protected]
Third, once the above command ran successfully. We can change the version of PHP used on our machine with the below command.
brew install shivammathur/php/[email protected]
Lastly, we need to add this to our path from the local terminal with the below commands.
echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/[email protected]/sbin:$PATH"' >> ~/.zshrc
Finally, to confirm the correct version of PHP is in use locally we run the command.
php -v
Hopefully, this article saves a lot of people a lot of soul searching in their early days as a developer in the PHP world!