I use PHPStorm as my primary tool for debugging PHP and am very pleased. So far I've been using Firefox to run the scripts, and PHPStorm catches breaks perfectly.
Now I have a situation where I am running a PHP script via command line (not browser) and want to know if there's a 开发者_JAVA技巧way to setup PHPStorm to catch breaks when running a PHP script via command line?
To enable PHP Debuging with Xdebug on the shell/command line with Phpstorm is very easy:
export XDEBUG_CONFIG="idekey=PHPSTORM"
In windows CLI, use set instead of export.
set XDEBUG_CONFIG="idekey=PHPSTORM"
Ensure Phpstorm is listening to the PHP Debug connections.
To disable debugging from command line end:
unset XDEBUG_CONFIG
This (PHPSTORM) is the default Phpstorm IDE-Key.
Please watch/vote the related PhpStorm issue.
At the moment configuration is a bit complicated. It should be possible to debug like described in the Zend KB, with a fake server and Php Remote Debug configuration in PhpStorm. Note that this tutorial has an error, you need to set QUERY_STRING like this (on Windows):
SET "QUERY_STRING=start_debug=1&debug_port=10137&debug_host=127.0.0.1&debug_stop=1&no_remote=1&debug_session_id=10000"
(note the difference in quoting which is important).
Set up PhpStorm like shown on the screenshots:
Press the Debug button on the main toolbar. PhpStorm will start listening for the debugger connections.
In the command line run your script:
d:\dev\zend\ZendServer\bin\php.exe d:\work\attaches\sample\helps.php
PhpStorm will hit the breakpoint:
This was tested on Windows with Zend Server installation, but should be similar on the other systems and with xdebug.
If you want to debug directly from PhpStorm, use Php Script Run/Debug configuration type. Your PHP instance configured for this project must have either Zend Debugger or Xdebug enabled in the configuration files.
PHP home and debugger mode can be specified in File | Settings | PHP
.
Just verified with Zend server installation (PHP home: d:\dev\zend\ZendServer\bin
) and Zend Debugger, works perfectly for me.
- Click Run.
- Click Edit Configurations...
- Click the green +
- Select PHP Script.
- Provide a name in the Name field.
- Provide the full path to your script in the File field.
- Click OK.
- Select the script you just configured in this dropdown:
- Click the run or debug button. Your script should run and it should catch any breakpoints that are set.
If you run the script, you can see output here:
If you debug the script, you can see output here:
Check that environments variables SERVER_NAME
and SERVER_PORT
are set. PHPStorm needs them to do the right mapping. Set them with export in the bash or manually in the phpscript. In both cases PHPStorm can find it then under $_SERVER['SERVER_NAME']
and $_SERVER['SERVER_PORT']
correctly.
None of these suggestions were working fine for me.
If you are in the same situation try this command (check the right php interpreter path)
/usr/bin/php -dzend_extension=xdebug.so -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 -dxdebug.remote_autostart=1 [PHP_SCRIPT]
For me (on MacOS) it worked that way:
export XDEBUG_CONFIG="idekey=12345"
On MacOS, I was using different bash_profile. I had to run following command first:
source ~/.bash_profile
This changed my php from built-in /usr/bin/php to the one installed via XAMPP. The PHPStorm's XDebug started working after above command.
精彩评论