How do i install different versions of php on mac?
Great post about having multiple PHP version in your console: https://getgrav.org/blog/macos-monterey-apache-multiple-php-versions. Show Few snippets from the post:
Since the latest MacOS Monterey 12 has removed the operating system, we need to manage PHP manually. I will show you a tip to install multiple PHP versions on MacOS Monterey 12. We will use Homebrew as package manager to do this. If you don’t have Homebrew installed, you might to set it up on your development machine. Let’s start with installing the first PHP version.
Install one PHP versionThe steps to install PHP is very simple, first, tap the PHP formulae and then select the appropriate PHP version to install.
Please replace Let say you want to install PHP version 7.3, you will need to issue this command:
Once done, restart the terminal and confirm php version:
Install multiple PHP versionsYou can install another PHP versions by issuing the same command above with different PHP version options:
Each PHP
version is set in a separate directory under
The default You can switch the link to different PHP version by using this command:
Switch PHP versionsInstead of using Homebrew link to set default PHP version, you can simply export the PHP bin directory to You can do this on the shell:
As you can see from the above commands, the default PHP command has been switched from PHP 7.3 to 8.1 easily. You can write an alias or a function to handle the export:
Then you can switch on the shell like this:
ConclusionThat’s how you install multiple PHP versions on MacOS Monterey 12 and manage them on the shell easily. Have fun! How do I install different versions of PHP?How to Install multiple versions of PHP?. Step 1 : Add ppa:ondrej/php to Ubuntu system. ... . Step 2 : Update the system. ... . Step 3 : Check php versions available. ... . Step 3 : Install different version of PHP.. Can I have multiple versions of PHP installed?Add a PHP Repository
So you'll need to add the PHP repository in your system to install the multiple PHP versions. Once the repository is up-to-date, you can proceed to install multiple PHP versions.
How do I switch between PHP versions?Upgrading or Downgrading PHP Versions. 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.. How do I upgrade PHP to 8.0 on Mac?Upgrading with Homebrew. Normal upgrade. brew upgrade php.. Upgrade with shivammathur/homebrew-php. brew tap shivammathur/php brew install shivammathur/php/[email protected]. To switch between versions, use the following command: brew link --overwrite --force [email protected]. ... . Next steps. Check the current version by running php -v : php -v.. |