Skip to content

Setting PHP7 Development on mac osx

Recently there have been a lot of changes to Homebrew in that there have been a number of packages renamed and improved. One of the packages that have been affected it PHP.

Specifically renaming the php71 to php@7.1, this has caused some confusion amongst the community on how to install PHP on Mac OSX and to enable xdebug.

In this post we will walk through the process of cleaning up a current installation of PHP on Mac OSX using Homebrew and enabling xdebug

If you have previously installed PHP on your Mac OSX using Homebrew you may want to take this opportunity to clean up your installation and reconfigure your machine with the latest packages.

Clean up old installs of PHP

We will use HomeBrew to install PHP 7.2 using the new Taps available. We will go ahead and uninstall all versions of PHP to ensure we only will have PHP installed via Homebrew.

First lets examine what PHP packages have been installed

Shell

We can now uninstall any packages that have been installed

Shell

Ensure we remove any old casks in Homebrew

Shell

Clean up all the launch agents to ensure there is no confusion later on.

Shell

We can now ensure Homebrew is cleaned up and updated

Shell

Check to see if there are any daemons running. If there are then reboot

Shell

Install PHP using Homebrew

Shell

By default this will install PHP 7.2.x (or whatever the latest edition of PHP is when you install it)

You will now be able to write and run applications using PHP. However, if you would like to be able to debug your PHP applications there are some additional steps you need to complete to install xdebug.

What is xdebug ?

Xdebug is an extension for PHP to assist with debugging and development. It contains a single step debugger to use with IDEs; it upgrades PHP's var_dump() function; it adds stack traces for Notices, Warnings, Errors and Exceptions; it features functionality for recording every function call and variable assignment to disk; it contains a profiler; and it provides code coverage functionality for use with PHPUnit.

Prior to moving the PHP taps in Homebrew it used to be possible to install xdebug and PHP7.2 at the same time using brew install php72-xdebug, sadly this is not the case, and from what I understand this won't be happening anytime soon.

PECL (PHP Extension Community Library) is now the source of xdebug and all future updates will available via PECL

How to install xdebug on Mac OSX

Installing xdebug via PECL is fairly straight forward, because if you have PHP7.2 installed you should be able to update your channel list first

Shell

This will check whether you already have xdebug installed

Shell

If xdebug is not install you can simply install it using

Shell

if you want to upgrade xdebug to the latest version  simply

Shell

Configure PHP to use xdebug

We need to add the following line to .

Shell

To find out where your php.ini file is

Shell

Which should return something similar too:

Shell

Configure PHP.ini

You can open the file using

Shell

The search for the

Shell

Then change it too

Shell

The additionally update the following

Shell

Configure PHPStorm

We predominantly use PHPStorm - Lightning-smart PHP IDE as our default PHP Development editor.
So it is worhtwhile ensuring you have enabled xdebug in PHP storm as your debugger - Xdebug Installation Guide

Summary

You should now have a complete PHP Development Environment configured on your Macbook.

Gary Woodfine
Latest posts by Gary Woodfine (see all)
Tags: