Hi everyone,
Recently, I've been working on a project that requires me to switch between different PHP versions on my macOS. I'm wondering if anyone here can guide me on how to do that using the command line. I have already installed multiple PHP versions using Homebrew and now I need to be able to switch between them depending on the project I am working on.
I have already tried searching online for a solution, but I couldn't find a clear and concise guide. It would be really helpful if someone could provide step-by-step instructions on how to switch between PHP versions using the command line on macOS.
Thank you in advance for your help!

Hey there!
Switching between different PHP versions on macOS using the command line can be a bit tricky, but I'll share my personal experience with you.
Instead of using Homebrew, I prefer using a tool called phpbrew. Phpbrew allows you to easily install and manage multiple PHP versions on macOS. Here's what worked for me:
1. First, make sure you have some prerequisites installed. You'll need Xcode command line tools, autoconf, and some other dependencies. You can install them using Homebrew by running:
2. Next, you can install phpbrew by running the following commands in your terminal:
3. Once phpbrew is installed and initialized, you can proceed to install your desired PHP versions. For example, if you want to install PHP 7.4, you can use the following command:
4. After the installation completes, you can switch between PHP versions using:
Replace `<version>` with the PHP version you want to switch to. For instance, `phpbrew switch 7.4` will switch to PHP 7.4.
5. To confirm that the switch was successful, you can run:
This should display the selected PHP version.
Remember to reload your shell configuration or open a new terminal window after switching versions for the changes to take effect.
I hope this alternative method using phpbrew works well for you! Let me know if you need any further assistance or have any questions.