PHP xdebug not working for Visual Studio Code - php

I have followed to the letter instructions for setting up xdebug with Visual Studio Code: https://blogs.msdn.microsoft.com/nicktrog/2016/02/11/configuring-visual-studio-code-for-php-development/
So all config files, files, etc are installed and tested as working outside of PHP.
Currently I am running PHP using the built in server (php -S localhost:8000 -t).
This works fine and I can see output in my browser. Similarly within VS Code I can run my code fine by running Ctrl + Shift + B. It also works inside Eclipse after installing PDT plugin.
Using phpinfo() I can see that xdebug is there and working fine. However, when I 'listen for XDebug' (I have changed launch.json to use port 8000) or press F5 all that happens is my status bar turns orange, the debug pane shows nothing and the debug buttons show pause/stop and I have to click one of these to quit the program, i.e. it does nothing.
What am I doing wrong?

Keep in mind that if you running PHP using the built in server, you must configure the php.ini file of the CLI (in my case is sudo nano /etc/php/5.6/cli/php.ini), not of Apache 2.

You shouldn't change launch.json to use port 8000, unless you've set xdebug.remote_port=8000 in your php.ini file. The port of the php server and xdebug are two different things. I guess that your xdebugremote_port is 9000 since using port 8000 for both things is impossible, so just change launch.json back to 9000.

Related

Xdebug remote.host IP changed when VPN Is active

I'm using PhpStorm with a docker container on a MacBook (Sierra 10.12.5) as my dev environment. When I'm not connected to my company VPN, the PhpStorm debug connection in PhpStorm looks like this:
docker://docker.companyurl.com/docker-developer:latest/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=192.168.10.1 /opt/project/testscript.php
This works fine, breakpoints are working and everything is good.
However, once the VPN connects (which I need to do if I'm accessing internal databases), the connect string changes to:
docker://docker.companyurl.com/docker-developer:latest/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=10.75.5.4 /opt/project/testscript.php
No breakpoints get triggered and the scripts completes without any debug session starting.
Does anyone know why the IP address changes? I've tried manually specifying the correct IP in the Xdebug options within PhpStorm, but instead of overriding the command line option it duplicates it, and it still doesn't break.
I am not able to work productively as long as this goes on, so any help is appreciated!
Apparently the problem is that phpstorm tries to read the IP address and other vars at run time-- if you're on the VPN it picks up your VPN-assigned IP instead of the actual IP.
So what appears to be a solution at the moment is:
1) open phpstorm preferences / Languages and Frameworks / PHP / Debug / Advanced Settings. Uncheck the box for "Pass configuration options through command line"
2) open phpstorm preferences / Languages and Frameworks / PHP, then click the ... near the PHP CLI interpreter. Click the ... near the Additional / Configuration Options item, and add a new param for xdebug.remote_host with a value of 192.168.10.1

How to debug PHP CLI scripts from the CLI

Does anybody know how to debug CLI PHP scripts from the CLI?!? I don't want to debug a PHP web page - I don't have a PHP web page. I don't want to debug a remote script either - I'm running/debugging right here on this system. I don't want to (at this time) try to get some IDE (Eclipse, PhpStorm or whatever) to debug a CLI PHP rather I just want to debug some PHP CLI script at the Linux command line itself. In Perl this would be simply perl -d <script.pl> <options>. Debugging a script, to me, is not figuring out compile errors or other simple things. To me it's setting break points, running code, examine the contents of variables and being able to arbitrarily execute or eval ('<php code>') at the debugger.
Sure later I'd like to configure this into my IDE of choice (at this time this is Eclipse) but I have not managed to get that working. Debugging from the CLI a PHP CLI script would be a good start for me.
Thanks.
I don't know why I'm limited to a character count when posting a comment. Perhaps I can add more text here.
Here's what I have tried in order to use xdebug and/or Zend debugger with Eclipse:
Base Eclipse version Mars.1 Release 4.5.
Eclipse PDT UI Plugin version 3.7.0.2015112
Tried installing xdebug using pecl install xdebug. Says I need to add "zend_extension=xdebug.so" to php.ini. Really? Which php.ini? I have several:
Andromeda:sudo find / -xdev -name php.ini
/etc/php5/cli/php.ini
/etc/php5/apache2/php.in
/opt/eclipse/plugins/org.zend.php.debug.debugger.linux.x86_64_5.3.18.v20110322/resources/php53/php.ini
/opt/eclipse/plugins/org.zend.php.debug.debugger.linux.x86_64_5.3.18.v20110322/resources/php5/php.ini
/opt/eclipse/plugins/com.zend.php.debug.debugger.php56.linux.x86_64_13.0.1.v20151112-2045/resources/php56/php.ini
Andromeda:
I put the zend_extension thing in both /etc/php5/cli/php.ini and /etc/php5/apache2/php.ini. Made a phpinfo.php page and I see Xdebug in there (yea!). Configure a Debug Configuration in Eclipse to use xdebug and try to debug:
Launching renameUser has encountered a problem. An internal error occurred during "Launching renameUser" java.lang.NullPointerException.
Oh goodie...
I had also installed the Zend Debugger and added the following to those same two php.ini files:
zend_extension=/usr/lib/php5/20121212/ZendDebugger.so
zend_debugger.allow_hosts=127.0.0.1/32, 192.168.0.0/16
zend_debugger.expose_remotely=always
Changed debug configuration to use Zend Debugger and attempted to debug. Received:
Error launching 'renameUser' The debug session could not be started. Please make sure that the debugger is properly configured as a php.ini directive.
Restarted Eclipse and now the debugger attempts to run but simply terminates with a 255 exit value attempting to run /opt/eclipse/plugins/org.zend.php.debug.debugger.linux.x86_64_5.3.18.v20110322/resources/php5/php-cgi. Why it's runnign php-cgi is beyond me. I said this was a CLI not a CGI. In any event I get the following when trying to run this from the command line:
Andromeda:/opt/eclipse/plugins/org.zend.php.debug.debugger.linux.x86_64_5.3.18.v20110322/resources/php5/php-cgi
/opt/eclipse/plugins/org.zend.php.debug.debugger.linux.x86_64_5.3.18.v20110322/resources/php5/php-cgi: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
Found a libiconv.so.2 in /opt/eclipse/plugins/org.zend.php.debug.debugger.linux.x86_64_5.3.18.v20110322/resources/lib and set LD_LIBRARY_PATH to include that but this just fails to launch the debugger at all stating to make sure that the debugger is properly configured as a php.ini directive... UGH!
Other odd stuff:
When Eclipse starts up it fails to open my RSE based project thus displaying edit buffers from the last run as empty
Eclipse will no longer exit! Select File: Exit. Nothing happens. Click on the X in the title bar - nothing happens. Now I have to kill it to close it!
When debugging on the command line you need to tell PHP you want to debug also
http://xdebug.org/docs/remote
says
export XDEBUG_CONFIG="idekey=session_name"
php myscript.php
assuming xdebug is enabled (it doesnt matter which .ini file its in, but there is a standard place per OS for this, usually in a conf.d folder called xdebug.ini which is auto included)
This allows you to debug a cmdline script.
Personally I use Vim with Vdebug extention (xdebug for vim) to debug and nothing other than a command line is needed
What worked for me was using dephpugger. I found the steps to get CLI debugging working here:
https://hackernoon.com/how-debug-php-applications-with-dephpugger-98cc234d917c
I had previously installed xdebug and tried out exussum's answer.
The steps I followed are included here for completeness.
Install dephpugger:
composer global require “tacnoman/dephpugger”:”dev-master”
Put dephpugger on the path:
export PATH=$PATH:$HOME/.composer/vendor/bin
make sure to include in the php file at the breakpoint:
xdebug_break();
open up 2 terminal instances. In one run:
dephpugger debug
In the other run
dephpugger cli /path/file.php
replacing /path/file.php with the path to your file. if you need command line arguments to the php script put the path and arguments in quotes. It still seems a little hacky. I think the real trick is to write in a language that has a better debugger built in.
exussums answer works for me.
In addition I have the following in /etc/php/7.0/cli/conf.d/20-xdebug.ini
zend_extension=xdebug.so
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_enable=true
#xdebug.remote_enable=false
And I had to do this: https://github.com/vim-vdebug/vdebug/issues/363
Being able to set break points in a PHP script requires some kind of debugger extension being loaded, either XDebug or Zend Debugger.
And then you need some kind of interface to this debugger to make your wishes about break points known. I am unfamiliar with the Perl debugging, but I haven't heard about any PHP CLI based debugging - it is always taking place in an IDE that is able to handle the debugging protocol of one of the extensions.
Of course there is the good old var_dump();die('hi'); debugging, but this does not include continuing code execution after the script ended. ;)

XAMPP not interpreting PHP code + Errors

First things first, when I open and run XAMPP this shows up
The issue is, when I try and open a .php file it doesn't work it simply just shows the code WITHIN the php file, the php itself does not work.
I have downloaded and uninstalled XAMPP 3 times today.
Any ideas?
This is a rookie mistake, Make sure the URL says localhost/index.php and not file:///C:/...
To fix the problem you need to change xampp port from 80. Normaly 81 works just fine.
Follow these steps to change the XAMPP server port number:
1) Stop the XAMPP server, if it is running already.
2) Open the file [XAMPP Installation Folder]/apache/conf/httpd.conf.
3) Search for: "Listen 80"
4) Change to (Example): "Listen 81"
5) Search : ServerName (Update this too)
6) Save
7) Restart XAMPP server and you are done.
Note:
Now your url is: www.localhost:81
You should just try reinstalling the operating system as well as xampp over again. My answer takes into consideration that you have already tried installing xampp three times. If you have a Mac just restart holding the command and r keys and then wait for the recovery center to come up. Then select reinstall osx. This requires internet. If you have windows there might be an install disk that came with the system and try reinstalling from the disk.
Problem is that port 80 is being used by some other application. If you have installed skype it would skype. We can manually change the port used by skype for that check the answer for this SO question How to solve WAMP and Skype conflict on Windows 7?
You can also make sure which appication is using port 80 by checking this SO question How to find which program is using port 80 in Windows?

PHP is not working on Windows after I completely installed it

I am trying to setup php 5.5.12 on my Windows server 2008 R2
I found this good tutorial that walks you step by step
http://www.youtube.com/watch?v=WUoqkPJEp4Y
After completing every step everything seems to be fine.
I created a file called phpinfo.php and put the following code into and placed it on c:/inetpub/wwwroot
<?php php_info(); ?>
But when I got localhost/phpinfo.php or http://127.0.0.1:80/phpinfo.php I get a 404 error. I do not know why it is not working. when I execute the following from commands from the command line it looks like it is working and I get many output with no error.
cd c:/php
php -i
In addition to the instruction, I added the following to the registry of windows
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\PHP]
"IniFilePath"="C:\\PHP"
Can someone tell me what else do I need to make get php up and running on windows?
This is what is using port 80 on my server
To use localhost or 127.0.0.1 you need apache installed on your system too.
You can download xampp or wamp they both come with PHP, MySql & Apache installed in them.

PHP-cgi stops working randomly without error log

I'm using nginx with (WT-NMP - portable mysql nginx php app.). Everything is working perfectly except php-cgi, it is stopping randomly and i have to start it again, in fact i realized that if i add to post my website quickly (in wordpress), it is definitely stopping. But sometimes it is stopping without for no reason, maybe there is a reason but i cant see because no error shows in errorlogs.
I searched on the internet and I found something about my problem but I couldn't use these methods on my windows server.
The solution I found: SET PHP_FCGI_MAX_REQUESTS=0 to the script that starts php-cgi.exe
#ECHO OFF
ECHO Starting PHP FastCGI...
SET PHP_FCGI_MAX_REQUESTS=0
SET PATH="D:\Program Files\php;%PATH%"
"C:\Program Files\php\php-cgi.exe" -b 127.0.0.1:9000 -c "C:\Program Files\php\php.ini"
Any idea about my problem? or any idea how to use this codes on my windows server. I searched for windows and found only one solution, it was about the IIS.
The proccess: adding PHP_FCGI_MAX_REQUESTS=0 to environment variables.
The following setting works fine for Windows 2012 R2 Server !!!
http://i.stack.imgur.com/HrIaO.jpg
Control Panel-> System->Advanced System Settings->Advanced->Environment Variables->System Variables-> New -> Variable Name: PHP_FCGI_MAX_REQUESTS & Variable Value: 0

Categories