Effortless Switching Between PHP Versions on macOS
To seamlessly test your application across various PHP versions (e.g., 5.3 to 8.2), you'll need to install the different versions and establish a mechanism for effortlessly switching between them.
Installing PHP Versions:
Utilize Homebrew, a package manager specifically designed for macOS:
<code class="bash">brew install php53 brew install php54 ... brew install php82</code>
Switching PHP Versions:
Once you have multiple PHP versions installed, employ Homebrew's link and unlink commands to toggle between them:
<code class="bash"># Switch to PHP 7.4 brew unlink php73 brew link php74</code>
This command unlinks PHP 7.3 from the system and links PHP 7.4 instead.
Verifying Version:
To confirm the active PHP version, execute the following command in the Terminal:
<code class="bash">which php</code>
This will display the path to the active PHP binary, indicating the version you have successfully switched to.
Note:
For the aforementioned commands to function, ensure you have installed all required PHP versions using Homebrew.
The above is the detailed content of How to Switch Between PHP Versions Effortlessly on macOS?. For more information, please follow other related articles on the PHP Chinese website!