Dave33
Dave33

Reputation: 481

Xdebug + MAMP not working (macOS Monterey + M1 CPU)

I just received my new MacBook Pro 16 inch with M1 CPU. Everything runs fine, but Debug gives me headaches.

For local (PHP) development I am using MAMP and doing so also installs Xdebug. Normally I also change Xdebug settings like so:

Files to change:

/Applications/MAMP/conf/php[version]/php.ini 
/Applications/MAMP/bin/php/php[version]/conf/php.ini
  1. Locate the xdebug section at the bottom of both of these files
  2. Uncomment zend_extension line in both files (remove the ;)
  3. Add the following lines to the xdebug section in both files:
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1    # Not safe for production servers
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true

Gotten from here: https://joshbuchea.com/mac-enable-xdebug-in-mamp

For Visual Studio Code I use these settings:

{
    "name": "Listen for XDebug",
    "type": "php",
    "request": "launch",
    "port": 9000
}

Has always worked 100% on an Intel chip. Now, with the M1, it doesn't. Press F5 so the debugger starts, but no stops at breakpoints occur.

The problem for me is that googling this tells me *) that the chip architecture doesn't match (x86/M1) and that I need to use pecl and such (bit new to this). But I'm using MAMP, which has already installed Xdebug.

Does anyone know how to fix this and help me get Xdebug up and running?

Development without debugging doesn't work...

*) https://crossrt.me/install-php-xdebug-on-m1-macbook-pro/

Xdebug failed install on Mac m1

Upvotes: 5

Views: 2443

Answers (2)

Keith Ivison
Keith Ivison

Reputation: 417

Ive had the same issue with Mac Mini and Sequoia, MAMP PRO and Sublime Text 3, been driving me nuts for best part of 2 weeks. Ive tried all the settings suggested but the one that made a difference for me was...

xdebug.mode = debug,develop
xdebug.client_host = 127.0.0.1
xdebug.client_port = 9003

The debug, develop was a big flag in getting var_dump to work properly. The MAMP documentation talks about 9000 as opposed to 9003 but it worked for me.

Hope this helps someone facing the same issue.

Keith

Upvotes: 1

Dave33
Dave33

Reputation: 481

Thanks to Derick I saw the error in my ways. Thanks very much! I had been (again...) trying for hours to get it to work.

Maybe someone else will come by and has the same issue, so I'll post what I did to finally fix it:

Apply the following to both of these files:

Applications/MAMP/conf/php[version]/php.ini
Applications/MAMP/bin/php/php[version]/conf/php.ini

1   Locate the xdebug section at the bottom of both of these files
2   Uncomment zend_extension line in both files (remove the ;)
3   Add the following lines to the xdebug section in both files:

xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9003
xdebug.client_host = "127.0.0.1"
xdebug.idekey = VSCODE

My (debug) launch.json file holds the following:

{
    "version": "0.3.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003
        }
    ]
} 

Works like a charm now :-)

Upvotes: 5

Related Questions