Home > Enterprise >  Using PHP xdebug with the PHP CLI binary from MAMP
Using PHP xdebug with the PHP CLI binary from MAMP

Time:07-05

I am using the PHP CLI binary of MAMP (ie. /Applications/MAMP/bin/php/php7.2.10/bin/php) to execute scripts from the Terminal. How can I use Xdebug to step thru a script that I execute this way?

So far I have read: https://joshbuchea.com/mac-enable-xdebug-in-mamp/ Getting Xdebug Working with MAMP and Mac which mentions how to enable xdebug but only through calling the script from a web server.

And this: Installing Xdebug for PHP CLI Which is on Xdebug with XAMPP which I unfortunately find difficult to extrapolate to MAMP.

Is there not a simple way like:

$ phpdebugger phpfile.php

( Instead of

$ php phpfile.php

)

Which will just start the debugging session with the file?

If xdebug is not suitable for this, is there another program to do this?

CodePudding user response:

  1. You can either set -dxdebug.start_with_request=yes:

    php -dxdebug.start_with_request=yes you-script.php
    
  2. Or, set xdebug.start_with_request=yes in php.ini (use php --ini to find out which file that is).

  3. Or, you can use the trigger environment variable:

    XDEBUG_TRIGGER=yes php your-script.php
    

CodePudding user response:

I do not use MAMP but what I use to debug PHP CLI is

export PHP_IDE_CONFIG="serverName=your.servername.com"
php -dxdebug.client_host=xx.xx.xx.xx -dxdebug.mode=debug -dxdebug.start_with_request=yes php_command_here

and obviously, add breakpoints to your code.

  • Related