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
We can now uninstall any packages that have been installed
Ensure we remove any old casks in Homebrew
Clean up all the launch agents to ensure there is no confusion later on.
We can now ensure Homebrew is cleaned up and updated
Check to see if there are any daemons running. If there are then reboot
Install PHP using Homebrew
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
This will check whether you already have xdebug
installed
If xdebug is not install you can simply install it using
if you want to upgrade xdebug to the latest version simply
Configure PHP to use xdebug
We need to add the following line to .
To find out where your php.ini file is
Which should return something similar too:
Configure PHP.ini
You can open the file using
The search for the
Then change it too
The additionally update the following
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.
- What is this Directory.Packages.props file all about? - January 25, 2024
- How to add Tailwind CSS to Blazor website - November 20, 2023
- How to deploy a Blazor site to Netlify - November 17, 2023