Install Multiple PHP Versions in OS X 10.11 EI Capitan

I assume you already have Apache, PHP and MySQL installed and enabled in your local box with default versions. This blog will teach you how to install Multiple PHP Versions in OS X 10.11 EI Capitan.


Homebrew- The package manager for OS X. Using the brew command we can easily add powerful features to mac.

XCode and the command line tools are required so we will install it through code or from Xcode via the Mac App Store first.

xcode-select –install


You can find out the full installation document from Homebrew Wiki but we will cover essential steps.

Run the following command in your terminal to install Homebrew.

$ ruby -e “$(curl -fsSL”

Please follow the terminals prompts and enter password where ever it is required. It may take few minutes but when complete please run the following command to ensure you have installed the brew.

$ brew –version


Please run the following command to confirm everything is working correctly:

$ brew doctor

The above command will instruct you if you need to correct anything.

Notice Older version of OS X install

Now you ready to install multiple PHP versions 5.4, 5.5, 5.6, 7.0

We will proceed by installing both PHP 5.4, PHP 5.5, PHP 5.6, and PHP 7.0 and using a simple script to switch between them as we need. First, though we have to run the following commands to install multiple versions:

$ brew install php54
$ brew unlink php54
$ brew install php55
$ brew unlink php55
$ brew install php56
$ brew unlink php56
$ brew install php70

Of course you can choose, which versions you would like to install. You can install as per your choice.

Also, if you want to do any changes in php.ini file then php.ini files are located in following directories:


Apache setup:

You have successfully installed the PHP versions but now you have to tell apache to use correct PHP versions. You will need to edit /etc/apache2/httpd.conf file and search for LoadModule php5_module libexec/apache2/ This is your current default PHP version, so you can comment out this line ex: #LoadModule php5_module libexec/apache2/ so below the other LoadModule lines, add this:

LoadModule php7_module /usr/local/opt/php70/libexec/apache2/

This will tell Apache to use PHP 7.0 to handle PHP requests. We will add the ability to switch PHP versions in my next blog.

Let’s restart Apache again, now that we have installed PHP:

$ sudo apachectl restart

Validating PHP Installation

The best way to test if PHP is installed and running as expected is to make use of phpinfo().

Simply create a file called phpinfo.php in your document root folder. In that file, just enter the line:

Point your browser to http://localhost/phpinfo.php and you should see a shiny PHP information page:

Install Multiple PHP Versions

Install Multiple PHP Versions

If you see a similar phpinfo result, congratulations! You now have Apache and PHP running successfully.

Note: In my next blog, I will show, how to add PHP Switcher Script to just change multiple PHP versions.


Leave a Reply

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