leojail
leojail

Reputation: 359

Xdebug failed install on Mac m1

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:

enter image description here

How can I solve this problem? Thanks

Upvotes: 11

Views: 12086

Answers (4)

Kyle Venn
Kyle Venn

Reputation: 8038

Solution for Macbook M1 as of 2024 04/28

  1. arch -arm64 pecl install xdebug
  • If 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 command
  1. This will end successfully with a path. Make note of it, you'll need it soon:
Build process completed successfully
Installing '/opt/homebrew/Cellar/php/8.2.4/pecl/20220829/xdebug.so'
  1. php --ini
  2. Open the ini file shown: open /opt/homebrew/etc/php/8.2/php.ini
  3. Remove the first line (if it says something about xdebug)
  4. Nav to conf.d directory (from php --ini) cd /opt/homebrew/etc/php/8.2/conf.d
  5. touch xdebug.ini
  6. open xdebug.ini
  7. Add the following code. Edit extension path to be the one from step 2
;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

  1. Open IntelliJ settings -> Languages & Frameworks -> PHP
  2. CLI Interpreter click the ...
  3. PHP executable: Paste this, but with your FULL version from above (ex. /opt/homebrew/Cellar/php/8.2.4/bin/php)
  4. Debugger extension: Your value from above (ex. /opt/homebrew/Cellar/php/8.2.4/pecl/20220829/xdebug.so)

Run Configuration

  1. 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"
    
  2. 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.
    
  3. 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

Joel Harkes
Joel Harkes

Reputation: 11661

Solution now on M1

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

Marinne
Marinne

Reputation: 361

If you encounter this:

  • file 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

Derick
Derick

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

Related Questions