After figuring out a way around the massive breaking change introduced by Xcode 11, it's now time to install Xdebug back on MacOS Catalina.
Update from January 6th 2021:
Using MacOS Big Sur? This solution should work for you too. But since Apple Deprecated PHP in MacOS Big Sur, you should probably rely on Homebrew now.
Update from June 30th 2020:
After some new investigation while trying to upgrade to a newer version of xdebug, I now believe most of the instructions in this post are not necessary. Before doing anything, you should check if xdebug.so already exists in /usr/lib/php/extensions/no-debug-non-zts-20180731/, which I believe is there by default (let me know if otherwise). If it does exist, you could skip to the Enabled support in PHP portion of this post.
Note that building xdebug from source code and actually trying to use that version of xdebug.so (for example by referencing the built file in xdebug/module/xdebug.so after using make install) with the build-in PHP should end up in a 'code signature' error. As described here and here, even after signing the binary, MacOS won't allow system binaries to interact with non-system binaries for security reasons. The only real solution to use a custom version of xdebug would be to compile and use you own instance of PHP instead of the build in one.
Once Xcode is properly registered on the system, you can delete file Xcode11.7.xip. Install VirtualBox’s Guest Additions. On macOS 10.15 Catalina, Guest Additions cannot be installed by default. Install XCode on macOS Catalina 10.15 on Windows PC. When you installed macOS Catalina 10.15 on Virtual machine. Then Power on the virtual machine. When you entered the macOS Catalina window click on the Apple Mac App Store. Once the App Store opened on the left-handed search bar type XCode and hit enter. If the answer is “yes”, then you will need to download and install Xcode from the Apple App Store. Xcode is a Mac application built by Apple, and it cannot be installed with Homebrew. Even if you answered “yes”, you will still need Homebrew and Ruby to install cocoapods or fastlane, for example, so you should read this guide.
Long story short, Apple decided to nuke /usr/include in MacOS Catalina, which has been the default location for C header file for ever in UNIX systems. Trying to install through PEAR / PECL will return an error as the compiler will look for necessary headers file in /usr/include. So the solution is to compile Xdebug manually, manually specifying the actual location of the header files, which are still provided by Xcode, just at a different location.
Xcode
The first step is to get Xcode from the App Store.
Once Xcode installed, we have to get the command line tools :
You might need to actually open Xcode at this point to finish installation and accept terms and conditions, especially if the previous command fails.
Finally, make sure the SDK is found. If the path you get differs from the one bellow, you might need to edit the path accordingly later on:
Manually Compiling Xdebug
Getting source
Let's compile 2.7.2, getting the source code from git. Alternatively, you can download the source from Xdebug site.
phpize
Next we need to make a copy phpize so we can edit the include path :
Find this line :
...and replace it with this line :
Run phpize:
You should now see something like this :
Configure & build
We can now configure :
...and run make using our custom SDK location defined as compiler flags. I used a variable to store the path to the SDK so it's easier to edit if it changes :
You might see some warning, just ignore it for now. Finally, we'll need to run :
Again, this command will fail because it can't move the extension to the right place. SIP will prevent it. But no worries, we'll take care of that manually at the next step. make install is still required as it will sign the *.so file.
Makefile to see which directory to include in your custom CPPFLAGS.
Enabled support in PHP
Once make install has been run, we can move the executable somewhere safe. I use /usr/local/php/extensions.
Then we edit the PHP configuration to enable Xdebug. Simply edit php.ini:
And we add the following at the bottom :
Restart built in server to be sure :
And finally test everything went fine :
If the above command returns nothing, then Xdebug is not available on your install. Go back the steps to find out what's missing.
References and thanks :
Update: I always appreciate the traffic, but the folks at MacPorts have their official installer for Catalina available now. You should use it:
https://www.macports.org/install.php
Updated on 2019/10/09 to work with the public release of Catalina.
Another year, another round of “Oh, shit! My software doesn’t run on the latest version of MacOS!” While MacOS steadily marches towards being a consumer friendly OS that alienates the hardcore users, we continue to try to beat back the tide with tools like MacPorts. I’ll be curious to see how things go with future versions of MacOS, now that there are reports that upgrading to Catalina will wipe out a users /opt/ folder.
Below you will find my steps for getting MacPorts compiled by hand on MacOS 10.15 Catalina. I am working on a clean install of Catalina and Xcode 11. If you are trying an upgrade, or using a different version, your experience may be different. If you run into problems post a comment and I’ll do what I can to help out.
And so, without further ado…
- Install MacOS Catalina
- Install XCode 11
- Launch XCode
- Agree to the license agreement.
- Enter your password when the authentication dialog box opens.
- Wait for it to finish installing components.
- Quit XCode
- Open a terminal window.
(CMD-Space terminal <return>) sudo xcode-select --install
(enter your user password)- When the pop-up opens asking for permission to install the command line tools, click “Install”.
- Agree to the license agreement, despite what it says will happen to your first-born.
- Back to your terminal window, inscribe these arcane incantations:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developersudo xcodebuild -license
(Space through the document, and then type ‘agree'<return> – The ghost of Steve Jobs will not start haunting you until at least New Years.)cd ~/Desktop
(A window will pop up asking for access to your desktop folder. Grant it, lest the imps be released.)curl -O https://distfiles.macports.org/MacPorts/MacPorts-2.6.1.tar.gztar -xzvf MacPorts-2.6.1.tar.gzcd MacPorts-2.6.1./configuremakesudo make install
(Enter your user password if prompted. You may not be prompted if you get through the above steps quickly.)echo 'export PATH=/opt/local/bin:$PATH' >> ~/.zshrcsource ~/.zshrcsudo port -v selfupdate
(Enter your user password if prompted. You may not be prompted if you get through the above steps quickly.)
At this point you are pretty much ready to start installing ports. I say pretty much, because there are two ‘optional dependencies’ that will make your life easier:
- Install Java from
https://www.java.com/en/download/mac_download.jsp - Install XQuartz X11 from https://www.xquartz.org/
OK, now you are really, really ready to install ports. 🙂
Take your fresh Catalina install out for a spin and let us know how it goes!
How To Install Xcode On Catalina
If this worked for you, could I ask a favor? Share a link to this article somewhere you think people would find it useful. Thanks!