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:
You can either set
-dxdebug.start_with_request=yes
:php -dxdebug.start_with_request=yes you-script.php
Or, set
xdebug.start_with_request=yes
inphp.ini
(usephp --ini
to find out which file that is).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.