Reputation: 359
I'm trying to install Xdebug on my Mac m1, I followed this page(https://xdebug.org/docs/install) to install. This is the step I followed:
step1 => go to cmd: arch -x86_64 sudo pecl install xdebug
step2 => go to php.ini delete this line of code
zend_extension="xdebug.so"
step3 => go to php.ini add this
[xdebug]
zend_extension=/opt/homebrew/lib/php/pecl/20190902/xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port="9003"
step4 => go to cmd: php -v
The error shows:
How can I solve this problem? Thanks
Upvotes: 11
Views: 12086
Reputation: 8038
arch -arm64 pecl install xdebug
ERROR: failed to mkdir /opt/homebrew/Cellar/php/8.2.4/pecl/20220829
, run rm /opt/homebrew/Cellar/php/8.2.4/pecl
then re-run above commandBuild process completed successfully
Installing '/opt/homebrew/Cellar/php/8.2.4/pecl/20220829/xdebug.so'
php --ini
open /opt/homebrew/etc/php/8.2/php.ini
cd /opt/homebrew/etc/php/8.2/conf.d
touch xdebug.ini
open xdebug.ini
;XDebug
zend_extension="/opt/homebrew/Cellar/php/8.2.4/pecl/20220829/xdebug.so"
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9003
;xdebug.mode=profile
xdebug.output_dir="/tmp"
Running php --version
should show you a line about xdebug (like so with Xdebug v3.2.1
)
🎉🎉🎉 Done 🎉🎉🎉
Bonus: Using in IntelliJ / PhpStorm
...
/opt/homebrew/Cellar/php/8.2.4/bin/php
)/opt/homebrew/Cellar/php/8.2.4/pecl/20220829/xdebug.so
)Run Configuration
Configure php.ini for Xdebug. Or just add this to a .user.ini
in the root of the project.
; Ensure the zend_extension points to the correct path for xdebug.so for PHP 8.3.4
zend_extension="/correct/path/to/xdebug.so"
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.client_host=127.0.0.1
xdebug.log="/tmp/xdebug.log"
Connect IntelliJ IDEA with Xdebug
a. Open IntelliJ IDEA and go to Settings/Preferences.
b. Navigate to Languages & Frameworks > PHP > Servers.
c. Add your server by clicking the + icon. Set:
Name: A meaningful name for your server.
Host: 127.0.0.1
Port: 3000 // or whatever port you're using locally
Debugger: Xdebug
Use path mappings to map your project root directory to the corresponding directory on the server.
d. Under Languages & Frameworks > PHP > Debug, ensure Xdebug is correctly setup:
Debug port: 9003 (match this with xdebug.client_port in php.ini).
Enable Can Accept External Connections.
Start listening for PHP Debug Connections:
Click on the telephone icon on the top right corner of IntelliJ IDEA or go to Run > Start Listening for PHP Debug Connections.
Upvotes: 25
Reputation: 11661
if pecl install xdebug
doesn't work. run it with sudo
command.
don't try the arch x84 command as it wont work anymore, since php is now build in arm cpu architecture.
Solution:
sudo pecl install xdebug
Upvotes: 1
Reputation: 361
If you encounter this:
which php
result shows Mach-O 64-bit executable arm64
.sudo pecl install xdebug
still resulted in the wrong architecture
problem.Try this:
arch -arm64e sudo pecl install xdebug
Note: arch -arm64
shown bad cpu type error in my case.
Upvotes: 3
Reputation: 36774
What happened here is that you built a x86_64
build of the extension, but homebrew likely used the arm64e
architecture. These architectures are not compatible.
You can verify what your PHP's architecture is with:
file `which php`
If that says arm64e
, then you need the original command from the documentation:
sudo pecl install xdebug
And if it's x86_64
, then you need the command modified for Apple's dual architecture:
arch -x86_64 sudo pecl install xdebug
For what it's worth, the docs say: On Apple M1 hardware, you might instead need to use..., not must.
Upvotes: 17