How can I easily switch between PHP versions on Mac OSX?

Avatar
C

Callum Davies

Senior Backend Engineer••
8300Views
5mRead
0Reactions

There are several ways to switch between PHP versions on Mac OSX, but one easy way is to use a tool like Homebrew and PHP switcher.

 

Here are the steps to follow:

1. Install Homebrew by running the following command in your Terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. Install PHP switcher by running the following command in your Terminal:

brew install php-switcher

3. Install the PHP versions that you want to switch between. For example, to install PHP 7.3, run the following command:

brew install [email protected]

4. Switch to the desired PHP version by running the following command:

php-switcher [version_number]

Replace [version_number] with the version number that you want to switch to. For example, to switch to PHP 7.3, run the following command:

php-switcher 7.3

Verify that the PHP version has been switched by running the following command:

php -v

This should display the version number of the currently active PHP version.

Note: Make sure to update your PATH environment variable to use the new version of PHP. You can do this by adding the following line to your .bashrc or .bash_profile file:

export PATH="$(brew --prefix)/opt/php@[version_number]/bin:$PATH"

Replace [version_number] with the version number of the PHP version you want to use.

Thank you for your time.

Connect with KoderSolution 🚀

Master modern software engineering, scalable architectures, and advanced backend systems.

What's your setup?What's your production setup for this scenario? Have you encountered similar architectural bottlenecks or edge-case gotchas?
Callum Davies
C
Written by•Senior Backend Engineer

Callum Davies

PHP & Laravel practitioner since v5.4. Big believer in thin controllers, explicit return types, and boring modular architecture that doesn't page you on weekends.

React to this article

Recommended Articles

View all articles