Installing Multiple Versions of PHP on Mac

A Guide to Installing Multiple Versions of PHP on Mac

Are you a Mac user who needs to work with multiple PHP versions? While it may seem like a daunting task, installing and switching between different versions of PHP on your Mac is easier than you might think. in this blog post we are discover Installing Multiple Versions of PHP on Mac, With the right tools and steps, you can have multiple PHP versions up and running in no time. In this guide, we’ll walk through how to install Homebrew, install multiple PHP versions, switch between them seamlessly, and configure your web server for optimal performance. So buckle up – by the end of this article, you’ll be a pro at managing multiple PHP installations on your Mac!

Installing Homebrew

Homebrew is a package manager for macOS that allows you to easily install and manage software packages on your computer. To get started with installing multiple versions of PHP, we need to first install Homebrew.

The easiest way to do this is by opening up the Terminal application on your Mac and running the following command:

/usr/bin/ruby -e “$(curl -fsSL”

This will download and install Homebrew onto your system. Once installed, you can use it to easily install different versions of PHP.

To make sure everything is working properly, run the command `brew doctor` in Terminal. This will check if any issues exist with your installation of Homebrew.

With Homebrew now installed, we’re ready to move on to installing multiple versions of PHP using the tool.

Installing Multiple PHP Versions

If you’re a macOS user and work with different PHP projects, installing multiple versions of PHP on your machine is essential. Luckily, this task is made easy with Homebrew.

To get started, ensure that Homebrew is installed on your computer. If not, simply enter the following command in the terminal:

“`/bin/bash -c “$(curl -fsSL”“`

Once Homebrew is installed, update it by running:

“`brew update“`

Next, install the required tap to access multiple PHP versions by typing:

“`brew tap exolnet/homebrew-deprecated“`

After installation of the tap completes successfully without any errors, run this command to display all available PHP versions:

“` brew search php@ “`

Now select which version(s) you’d like to install using the following command (replace x.x with the desired version number):

“` brew install [email protected] “`

And finally switch between them as needed for each project.

Switching Between PHP Versions

Switching between PHP versions on a Mac is a straightforward process. Once you have multiple versions of PHP installed, it’s easy to switch between them depending on your needs.

The first step is to determine which version of PHP you want to use for your current project. You can do this by checking the requirements of the application or framework that you’re working with.

Once you’ve determined the version of PHP that you need, open Terminal and enter the command “brew link –overwrite [version]”. Replace “[version]” with the specific version number that you want to use.

After running this command, Homebrew will create symbolic links from /usr/local/bin/php, /usr/local/bin/php-cgi and other binaries in /usr/local/Cellar/[php-version]/bin directory into /usr/local/bin/, so any calls will be redirected automatically.

To verify that everything is working correctly, run “php -v” in Terminal again and check if it displays as expected. If not, try restarting your web server or shell session.

Switching between different versions of PHP on a Mac using Homebrew is pretty simple once set up correctly. It allows developers more flexibility when developing applications and ensures compatibility with older projects still requiring previous versions of PHP.

Configuring Your Web Server:

Now that you have multiple versions of PHP installed on your Mac, it’s time to configure your web server. The most popular web server for Mac users is Apache, which can be easily installed using Homebrew.

Once you have Apache installed, navigate to the httpd.conf file located in /usr/local/etc/httpd/ and open it with your preferred text editor. In this file, you’ll need to update the LoadModule and AddHandler directives to include each version of PHP that you want to use.

For example, if you have PHP 7.4 and 8.0 installed, add the following lines:

LoadModule php7_module /usr/local/opt/php@7.4/lib/httpd/modules/

AddHandler php7-script .php

LoadModule php8_module /usr/local/opt/php@8.0/lib/httpd/modules/

AddHandler php8-script .php

Save the changes and restart Apache by running “sudo apachectl restart” in Terminal.

You should now be able to switch between different versions of PHP by editing the appropriate line in httpd.conf or creating separate virtual hosts for each version. Congrats! You’re now ready to start developing with multiple versions of PHP on your Mac!


After following the steps outlined in this guide, you should now be able to install multiple versions of PHP on your Mac with ease. By utilizing Homebrew and its formulae system, it is possible to have different PHP versions coexisting on the same machine.

Switching between these versions can be done easily using commands in the terminal. It’s important to note that after switching between versions, you may need to restart your web server for the changes to take effect.

Additionally, configuring your web server correctly is crucial for getting everything working properly. Make sure that each virtual host or site points to the correct version of PHP and that any necessary extensions are enabled.

By having multiple versions of PHP available on your Mac, you can ensure compatibility with different projects and avoid conflicts between dependencies. This flexibility allows developers to work more efficiently and effectively.

Being knowledgeable about installing multiple PHP versions on a Mac will greatly benefit any developer who needs this capability.

Related Peoples Also Find



Question: Can I run several versions of PHP at the same time?

Answer: One of the most common questions that arise when it comes to installing multiple versions of PHP on a Mac is whether or not you can run several versions at the same time. The answer is yes, you can!

Thanks to tools like Homebrew and phpbrew, it’s possible to install various versions of PHP side by side on your machine. This allows developers to switch between different PHP releases for testing purposes or running projects with different requirements.

Homebrew makes installing and switching between different PHP versions incredibly easy. You just need to run a few commands in Terminal, and voila! You have access to all the installed versions.

Meanwhile, phpbrew provides more granular control over each version of PHP, enabling users to configure extensions and settings independently for each one.

The ability to run several PHP versions simultaneously means developers can test their code against multiple releases without having to uninstall/reinstall every time they want to use a different release.

Question: How to switch between PHP versions?

Switching between PHP versions on your Mac is a fairly straightforward process. First, you need to make sure that all the necessary PHP versions are installed and properly configured.

Once you have multiple versions of PHP installed on your Mac, you can switch between them using the Terminal application. Open up Terminal and type in the following command:

sudo update-alternatives –config php

This will display a list of available PHP versions that you can choose from. Simply enter the number corresponding to the version that you want to use and press Enter.

You may also need to restart any web servers or other applications that rely on PHP for changes to take effect.

It’s important to note that some web development environments, such as MAMP or XAMPP, may have their own methods for managing multiple PHP versions. Be sure to consult their documentation if this applies to your setup.

Posts created 396

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top