How to change XDEBUG_CONFIG idekey value in PhpStorm? - php

I have configured PhpStorm to connect to a remote web server. I am running phpunit for unit tests. I have xdebug running and have created an ssh tunnel for debugging. I know xdebug is running as I am able to click and run a phpunit test (with breakpoint set) by just clicking the run button (after turning on listening for PHP debug connections). However if I instead choose the Debug option in PhpStorm I get connection errors.
Enabling debug messages to the PhpStorm log file I see that the command being sent is:
DEBUG - ellij.ssh.SshConnectionService - Executing SSH command:
cd /[path to project files];
exec env "IDE_PHPUNIT_CUSTOM_LOADER"="/[path to autoloader]/autoload.php" "JETBRAINS_REMOTE_RUN"="1" "XDEBUG_CONFIG"="idekey=17650" /usr/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9002 -dxdebug.remote_host=[ip address] /[path to phpunit]/phpunit/phpunit --configuration /[path to phpunit xml file]/phpunit.xml --filter '/(::myTestClassMethod)( .*)?$/' 'another method being tested' /[path to unit test file]/myUnitTest.php --teamcity within SshjSshConnection([blah]#[foo])#bar
My php.ini settings are expecting idekey=PHPSTORM but I'm seeing a numeric key in the command line that keeps changing for each attempt.
I'm assuming these two values for idekey need to match. If that's correct how do I do that?
Thanks

They don't need to match. In fact, PhpStorm is just overriding it here so that it can match against what it expects.
I don't understand why it does that, as IDE Keys are (currently) only used in combination with DBGp proxies.
As you don't describe what "connection errors" are, it's not really possible to provide an answer to that part of the question yet.

Related

"-1" file created in app root directory when running php artisan

I am running Laravel on Homestead, and whenever I run any php artisan XXX command, the file named -1 is created in the root directory of the app.
Contents of the file are similar to these ones:
Log opened at 2017-12-22 13:54:00
I: Connecting to configured address/port: 10.0.2.2:9000.
E: Time-out connecting to client. :-(
Log closed at 2017-12-22 13:54:00
I am 99% sure it is related some changes I made in my failed attempts to make XDebug breakpoints work with artisan commands. I have exported some shell variables, as recommended in this answer, but when I run export -p I don't see any of them.
Did anyone have a similar issue? What setting can be causing such behavior?
Following the suggestion of LazyOne, I found the answer:
It seems that paths in .ini file have to be absolute. So instead of:
xdebug.remote_log=~/code/xdebug.log
I had to set it to:
xdebug.remote_log=/home/vagrant/code/xdebug.log
and now it works as supposed to.

Drupal 8: Debugging tests with XDebug and PHPStorm - cennot step through

I'm trying to debug my Drupal 8 tests with XDebug, but if I run them with XDebug switched on, I cannot step into the test. I execute the following command:
vendor/bin/phpunit -c core
modules/permissions_by_term/tests/src/Kernel/SelectTermTest.php
PHPUnit reports me here:
"Can't find a source position. Server name 'localhost' doesn't exist."
My settings in the PHP.ini file are looking as follows:
xdebug.remote_enable=true xdebug.profiler_enable=0
xdebug.idekey=PHPSTORM xdebug.max_nesting_level=256
xdebug.remote_autostart=true
Can anybody share here some experience?
I got it to run. I had to do some more settings.
First, create a new PHP Remote Debug under the Run Configurations (The ZeroConfiguration didn't work for me). Define a Server with the name you want (here "TestServer") and enter PHPSTORM as Ide Key.
Also see the Jetbrains documentation: https://confluence.jetbrains.com/display/PhpStorm/Debugging+PHP+Web+Applications+with+Run+Debug+Configurations
Enable the option "Break at first line in PHP scripts" in under the RUN menu .
It can be possible that you need to override the file mapping. (In my case PHPStorm is not able to detect file mapping automatically) (See: https://www.jetbrains.com/help/phpstorm/10.0/override-server-path-mappings-dialog.html). It's is within same dialog where the server was created.
Start the Remote Debug Session with clicking on the corresponding icon.
Then you should be able to run PHPUnit with this command:
PHP_IDE_CONFIG="serverName=TestServer" XDEBUG_CONFIG="idekey=PHPSTORM" vendor/phpunit/phpunit/phpunit -c YOUPHPUNITXMLCONFIG
Set the PHP_IDE_CONFIG corresponding to your settings.
Set breakpoints where you want to stop.
I hope I could help you.
Nico

Debug php executed from rabbitmq queue with xdebug

I'm trying to debug PHP code executed by a RabbitMQ consumer.
xdebug is working fine in both CLI and http, but it fails when something is executed from a queue. I have set the following trace:
ini_get("xdebug.idekey")
ini_get("xdebug.remote_host")
ini_get("xdebug.remote_connect_back")
ini_get("xdebug.remote_mode").
ini_get("xdebug.remote_autostart")
php_ini_loaded_file()
getenv("XDEBUG_CONFIG")
It prints:
""
localhost
1
req
0
/etc/php5/cli/php.ini
xdebug.idekey=sublime.xdebug
xdebug.remote_host=10.5.223.108
xdebug.remote_connect_back=0
xdebug.remote_mode=req xdebug.remote_autostart=1
So the problem seems to be that it is ignoring the environment variable XDEBUG_CONFIG and is using the values in the cli ini file. I don't have permissions to modify the ini file, and the XDEBUG_CONFIG variable works fine when executing something via CLI.
Any ideas why XDEBUG_CONFIG is being ignored when the code is executed from a queue?
Xdebug and RabbitMQ consumer commands
To make your IDE aware of the connection you need to prefix the command with the environment variable:
XDEBUG_CONFIG="put-here-your-value" php my-script.php

How to fix the "unrecognized option --run" on NetBeans running PHPUnit

I'm trying to run the PHPUnit into the NetBeans 8.0.2.
If I run # phpunit inside my folder tests all tests run. So it's seems been set right.
But in the NetBeans output I always got:
"C:\nginx\php\5.6.12\php.exe" "C:\nginx\php\5.6.12\phpunit.phar" "--colors" "--log-junit" "C:\Users\...\AppData\Local\Temp\nb-phpunit-log.xml" "--bootstrap" "E:\var\www\...\tests\TestHelper.php" "--configuration" "E:\var\www\...\tests\phpunit.xml" "C:\Program Files\NetBeans 8.0.2\php\phpunit\NetBeansSuite.php" "--run=E:\var\www\...\tests\app\utils\FormatUtilTest.php"
PHPUnit 4.8.2 by Sebastian Bergmann and contributors.
unrecognized option --run
Done.
Maybe the "--run message" it's right, because this command doesn't exist in the PHPUnit manual. But if is that so, how to create another script for the NetBeans execute the tests?
I ran into the same issue yesterday after a PHPUnit update. So I reverted back to PHPUnit 4.7.7 for now, until this is fixed in NB.
I too have encountered this error causing the latest version of PHPUnit not to work with NetBeans v8.0.2.
Further investigating this issue has resulted in determining that there is an incompatibility between NetBeansSuite.php and the latest version of PHPUnit.
The error 'unrecognized option --run' is being thrown by the phpunit.phar and not being thrown by NetBeansSuite.php. I also do not believe the NetBeansSuite.php is even being executed.
phpunit.phar, line 63816 or 63894, is where the exception is being thrown.
Until this is fixed, PHPUnit will not work from NetBeans v8.0.2.
#Pablo: I thank you for opening an issue and have commented on your issue.
PHPUnit v4.7.7 works correctly.
Opened a bug report: https://netbeans.org/bugzilla/show_bug.cgi?id=254276
The answer is: This was indeed a bug in NB and is now fixed in nightly.
Possible solutions:
Upgrade to latest nightly from http://bits.netbeans.org/dev/nightly/
Use PHPUnit 4.7.7 as mentioned by Luuk
"--run" option is used in the NetBeansSuite.php for running tests. So, you should submit that to NetBeans bugzilla [1] if you want to avoid that.
[1] https://netbeans.org/community/issues.html (PHP/PHPUnit)
2019 and the problem still exists. Downgrading PHPUnit is no option anymore today. So I created, as a workaround, a wrapper script for phpunit which takes care of removing the bad parameters.
It also removes the NetBeansSuite.php file completely because it does the same a call directly to the phpunit script would.
My setup is Windows Netbeans 11, Windows PHP 7.3, and a cygwin wrapper (because it's bash code). If somebody feels like porting this to native windows, please leave a comment here.
#!/usr/bin/env sh
# modified phpunit script originally from vendors dir
# 1. cygwin default search path is bad in my installation...
PATH="$PATH:/bin:/usr/bin"
# original code, only adjust the ../../ to match your installation.
# the directory this is run in is where the wrapper script resides
dir=$(cd "${0%[/\\]*}" > /dev/null; cd "../../vendor/phpunit/phpunit" && pwd)
if [ -d /proc/cygdrive ] && [[ $(which php) == $(readlink -n /proc/cygdrive)/* ]]; then
# We are in Cgywin using Windows php, so the path must be translated
dir=$(cygpath -m "$dir");
fi
# fix netbeans parameters
while [ $# -gt 0 ]; do
case "$1" in
*NetBeansSuite.php) shift;;
--run=*) PARAMS="$PARAMS ${1#--run=}"; shift;;
--) shift ;;
*) PARAMS="$PARAMS $1"; shift;;
esac
done
"${dir}/phpunit" $PARAMS
You have to adjust both occurrences of "../"s to your folder structure.
This solution works with ALT-F6 (run all tests), right clicking a test folder "Run Tests" and also single test files right click "Run".
The setting for "Netbeans: Tools/Options/Frameworks & Tools/PHPUnit" is then:
C:\cygwin\bin\bash.exe /cygdrive/c/workspace/Project/src/cli/phpunit
Adjust these path names to your needs, again.
HTH,
M.

Apache PHP script to Start Tomcat Server in Linux

I made a php script to start Tomcat Server (catalina.sh start) thats works well from command line in Linux. It was run as ROOT with a different set of ENV.
However, I would like to do the same from the Web, Please note due to security issues, this script would only be accesible via localhost (for administration only), so we ironed out the security issue.
Problem is, Tomcat is not starting (we could confirm that from the logs, nothing was initiated). We coded lots of Echo around catalina.sh and its providing the right echo output.
Im sure theres an easier way to do this. Any Ideas?
The PHP script does the following:
Changes Dir to th Tomcat Bin
Starts Catalina.sh Script vis startup.sh
OUTPUT FROM COMMAND LINE PRINT ENV:
ORBIT_SOCKETDIR=/tmp/orbit-root
HOSTNAME=localhost.localdomain
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
XDG_SESSION_COOKIE=c111d8f81ff89709b78252c50000000d-1338310776.433586-1797694621
GTK_RC_FILES=/etc/gtk/gtkrc:/root/.gtkrc-1.2-gnome2
WINDOWID=73400323
QTDIR=/usr/lib/qt-3.3
QTINC=/usr/lib/qt-3.3/include
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
SSH_AUTH_SOCK=/tmp/keyring-bsFAQz/socket.ssh
GNOME_KEYRING_SOCKET=/tmp/keyring-bsFAQz/socket
USERNAME=root
SESSION_MANAGER=local/unix:#/tmp/.ICE-unix/1788,unix/unix:/tmp/.ICE-unix/1788
PATH=/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
MAIL=/var/spool/mail/root
DESKTOP_SESSION=gnome
PWD=/programs/tomcat/bin
GDM_KEYBOARD_LAYOUT=us
GNOME_KEYRING_PID=1779
LANG=en_US.UTF-8
GDM_LANG=en_US.UTF-8
GDMSESSION=gnome
HISTCONTROL=ignoredups
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SHLVL=3
HOME=/root
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
LOGNAME=root
QTLIB=/usr/lib/qt-3.3/lib
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-9HtQtRhCr9,guid=e1755bf07ea8a916f0a4e3f70000001c
LESSOPEN=|/usr/bin/lesspipe.sh %s
WINDOWPATH=1
DISPLAY=:0.0
G_BROKEN_FILENAMES=1
COLORTERM=gnome-terminal
XAUTHORITY=/var/run/gdm/auth-for-root-IT2DiY/database
_=/usr/bin/printenv
OUTPUT FROM APACHE PRINT ENV:
TERM=xterm
PATH=/sbin:/usr/sbin:/bin:/usr/bin
PWD=/programs/tomcat/bin
LANG=C
SHLVL=4
_=/usr/bin/printenv
try using exec()
exec('full path to your script')

Categories