Troubleshoot PHPUnit xdebug remote debugging using PHPStorm

I am trying to get Xdebug remote debugging to work, I am using PHPStorm as my IDE. My web server / code is hosted on a remote machine (amazon ec2).

I have the following lines in my php.ini on my remote server (PHP CLI, as I am debugging PHPUnit)

zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so xdebug.remote_enable = 1 xdebug.remote_autostart = 1 xdebug.remote_handler = dbgp xdebug.remote_mode = req xdebug.remote_connect_back = 1 xdebug.remote_port = 9000 

As I program from my home network, I opened port 9000 on my personal router. I have a PHPStorm xdebug server installed that points to a remote server on port 80 with Xdebug as a debugger.

Now when I try to debug the PHPUnit test from PHPStorm, it just says' Waiting for incoming connections with ide key '12115' In addition, it selects a random ide key every time (I want to hope that PHPUnit installs idekey on the server itself)

I am trying to get this to work for more than 10 hours, I tried to define my specific remote_host in php.ini instead of using remote_connect_back, but it also did not work. I tried installing idekey in php.ini, and that didn't work either.

Is there anyway to confirm that Xdebug is working as intended on the web server side? How can I check my Xdebug settings without using Phpstorm, I don’t know if this is a connection problem between my home network and the remote server or what.

Any guidance to help narrow down the problem would be great.

+4
source share
5 answers

I know that the question is a little old, but since I had the same problem and found a solution, I decided to post here everyone who is interested.

My solution is largely based on what Rafael Doms presented in his blog post: Debugging PHPUnit tests in NetBeans using XDebug

Environment

  • IDE: PHPStorm 6.0.2
  • Server: WAMP Server (32-bit and PHP 5.4.3) 2.2E
  • XDebug: 2.2.2

Xdebug

 zend_extension=c:\wamp\bin\php\php5.4.3\ext\php_xdebug-2.2.2-5.4-vc9.dll xdebug.extended_info=1 xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000 xdebug.remote_log=c:/wamp/tmp/xdebug/xdebug_remote.log 

The above configuration parameters are included in the php.ini file for the CLI. To install WAMP by default, the full path to this file is: C: \ wamp \ bin \ php \ php5.4.3 \ php.ini

Phpstorm

First of all, you should create a “Server Configuration” (google “Creating a Server Configuration - JetBrains” for the white paper on this), specifying “Xdebug” as “Debugger”.

Then create a new "Remote PHP debugging configuration" (google "Creating and editing start / debug configurations - JetBrains" for an official white paper on this), specifying the following values ​​in the "Configuration" section:

  • Servers: server created above
  • True Key: PHPSTORM

Now select this configuration and click on the "Debug" button (or "Shift + F9"). PHPStorm displays the Debug panel and displays the message: Waiting for an incoming connection with ide key "PHPSTORM"

Finally, run your PHPUnit test. There are several ways. One of them:

  • Right-click the name of the file where the PHPUnit test is located.
  • Select "Run File Name"

What is it! XDebug will take control here.

+5
source

If you are using Xdebug 2.2.0RC1, then the remote debug log (http://xdebug.org/docs/all_settings#remote_log) will notify you of failed connection attempts. This can determine if the problem is on the Xdebug side or the phpstorm side.

+1
source

In my case, the problem was that I had the xdebug configuration in /etc/php/fpm/php.ini , but php-cli uses /etc/php/cli/php.ini .

0
source

Since it took me a day to get it to work, I will summarize what in the study:

Make sure you change the correct php.ini, XAMPP uses a different version of php.ini and php than the one that was preinstalled on OS X Mavericks.

Define the log file, and if nothing is written to it, you will change the wrong php.ini

In phpstorm, you can check the connection to the server and get an idea if you are working on the correct php.ini or what is still wrong.

You need to change the settings for debugging (it may be worth changing the port to 9001), the server, everything in phpstorm settings and configure.

You have to set the php language level and interpreter (use the one that uses your mysql php apq configuration), for example. / Application / XAMPP / xamppfiles / bin, click ... to see Php and if a debugger is connected. You may need to use a different version of xdebug.

In servers, you must define Host as

 http://yourdefinitionofprojectonlocalhost 

usually with port 80 and Xdebug. It is important to check the remote environment.

In the debug section, you can set the Debug port, if you change it to 9001, change it and in php.ini, select Can Accept external Connections.

If you did not enable the "Start listening to PHP Debug Connection" function, you have no hope of making it work (the icon in the upper right corner or in the "Run" menu).

In Edit Configurations ... you must define a PHP web application in order to be able to use Debug in the Run menu.

It took me a day to make it work. The main problems associated with editing the wrong php.ini (do not forget to restart apache after editing) and the fact that xdebug did not work with the php version.

As you can see, I tried many options in my php.ini and ended up using the xdebug version found in my mamp directory:

 ;zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so" zend_extension="/Applications/MAMP/bin/php/php5.5.10/lib/php/extensions/no-debug-non- zts-20121212/xdebug.so" [xdebug] ;xdebug.var_display_max_children = 999 ;xdebug.var_display_max_data = 99999 ;xdebug.var_display_max_depth = 100 ;xdebug.remote_enable = 1 ;xdebug.remote_port=9001 ;xdebug.profiler_enable=1 xdebug.remote_connect_back=0 ;xdebug.remote_handler=dbgp ;xdebug.remote_host=localhost ;xdebug.profiler_output_dir=/Users/mypath/tmp xdebug.remote_log=/Users/mypath/xdebug.log ;xdebug.remote_mode=req xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_host=127.0.0.1 xdebug.remote_port=9001 

I wish you faster success than me.

0
source

In my case, it started working when I changed the port to 9000. The phpstorm phpunit command now was: /usr/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9002 -dxdebug.remote_host=10.0.2.2/var/www/application/vendor/phpunit/phpunit/phpunit --bootstrap/var/www/application/tests/Bootstrap.php --configuration/var/www/application/tests/phpunit.xml <testfile> --teamcity

0
source

Source: https://habr.com/ru/post/1402788/


All Articles