如何在搭载Apple M1芯片的本地MacBook上启用Xdebug?
Hey there! Let's get Xdebug up and running on your Apple M1 Mac with PHP 8.0.10 CLI. I've gone through this setup a few times, so here's a straightforward guide that should work smoothly:
Install Xdebug via PECL
Fire up your terminal and run this command. Since you're on an M1 chip, we'll enforce the arm64 architecture to avoid any mismatch issues:arch -arm64 pecl install xdebugOnce installation finishes, it’ll output the path to the
xdebug.sofile (usually something like/opt/homebrew/lib/php/pecl/20200930/xdebug.so). Jot this down — you’ll need it in the next step.Locate your PHP configuration file
First, let’s find whichphp.iniyour CLI PHP is using. Run:php --iniLook for the line labeled
Loaded Configuration File— that’s the file we need to edit.Enable Xdebug in php.ini
Open the config file in your preferred editor (I use nano for quick terminal edits, but VS Code works too):nano /path/to/your/php.iniScroll to the bottom and paste these lines, replacing the
zend_extensionpath with the one you noted earlier:[Xdebug] zend_extension="/opt/homebrew/lib/php/pecl/20200930/xdebug.so" xdebug.mode=debug xdebug.client_host=localhost xdebug.client_port=9003 xdebug.start_with_request=yesA quick breakdown of these settings:
xdebug.mode=debug: Turns on core debugging functionalitystart_with_request=yes: Triggers Xdebug automatically whenever you run a PHP script from the CLIclient_port=9003: This is Xdebug 3’s default port — most IDEs support this out of the box, but you can adjust it if needed.
Verify Xdebug is active
Run this command to confirm everything’s working:php -vYou should see a line in the output like this:
with Xdebug v3.x.x, Copyright (c) 2002-202x, by Derick Rethans
If that shows up, you’re all set!
Quick IDE setup tip
If you’re using VS Code, PHPStorm, or another IDE, just make sure the debug port in your IDE’s settings matches9003(Xdebug 3 switched from the old 9000 port used in Xdebug 2). No extra hoops to jump through for basic CLI debugging after that.
内容的提问来源于stack exchange,提问作者itsmeguruharry

