I have managed to initiate php-cli script debug session from the IDE itself, but I need to start the debugging session from the shell / command line. These are rather complex maintenance PHP scripts which tak开发者_运维百科e a lot of input parameters, so entering arguments from within Netbeans is a bit cumbersome.
I have done it before with Zend studio: https://zend18.zendesk.com/hc/en-us/articles/203838096-Debugging-PHP-CLI-Scripts, but now I need to get it working with Netbeans.
I got this working on Ubuntu/Netbeans by:
- copying the xdebug config lines from the /etc/php5/apache2/php.ini file into /etc/php5/cli/php.ini
- setting an environment variable with the name of the debug session (you can get this from the query string in the url of the page netbeans launches when you start debugging) so the command is:
export XDEBUG_CONFIG="idekey=netbeans-xdebug"
Then it's simply a case of starting debugging in netbeans and doing php myscript.php
at the command line.
Note: If you want to debug remotely using netbeans you need to use Debug File on the file that is being run from the command line, not normal Debug.
Add xdebug.remote_autostart=On
to your php.ini file or add -dxdebug.remote_autostart=On
as parameter to the PHP binary call (php -d... script.php
).
See http://xdebug.org/docs/remote
I will put all together, the following is that works for me.
file:
/etc/php5/cli/php.ini
zend_extension="/usr/lib/php5/20121212/xdebug.so" -> xdebug bin path
xdebug.remote_enable=on
xdebug.remote_host=127.0.0.1
xdebug.remote_handler="dbgp"
xdebug.remote_mode="req"
xdebug.remote_port=9000 -> same port configured in netbeans debugging tab
xdebug.idekey="netbeans-xdebug" -> same ide configured in netbeans debuggin tab
xdebug.remote_autostart=1
then, without any other parameter
php script.php
I had the same problem, my solution was this:
- Environment: Netbeans 8.2 under windows (apache+php)
- Assuming you already have PHP and NetBeans configured to debug code using Xdebug (http://wiki.netbeans.org/HowToConfigureXDebug#Notes_on_Windows_Configuration)
- On netbeans create new Configuration (“Project Properties” > “Run configuration” > “New…”
- In the new Configuration set Do Not Open web Browser (“Advanced” > “Do Not Open web Browser”)
- Set active the new configuration created (drop down in tool bar)
- Set breakpoint for debug
- Open debug (CTRL+F5)
- Open Terminal window (“Tools” > “Open in Terminal”)
- Type in terminal: $ export XDEBUG_CONFIG="idekey=netbeans-xdebug" (the value "netbeans-xdebug" must coincide with “Tools” > “Options” > “Debugging” > “Session ID”)
- Type in terminal: $ php.exe -f "C:\Apache24\htdocs\www.SiteName\ScriptName.php" -- "Arg1=x&Arg2=y"
- Follow debug…
I had the same problem my solution was this:
In Netbeans > the project window > right click on the php project > properties > Run configuration. Create a New Configuration.
Fill the correct values:
- Run as "script"
- set php interpreter
- change index file in my case it was "cron/index.php".
You can use the Dephpugger project if you dont want to configure xDebug for your IDE (i hate configurations).
https://github.com/tacnoman/dephpugger
You can run the debugger in terminal, like ipdb for Python and byebug for Ruby.
Make sure you also setup DBGP_IDEKEY value, because usually it is not idekey. For example on Linux:
export DBGP_IDEKEY="netbeans-xdebug"
export XDEBUG_CONFIG="netbeans-xdebug=netbeans-xdebug"
精彩评论