I need to debug my Laravel application and as I searched Xdebug seemed to be the best option out there. Up to now I couldn't setup a session to the debug my app and I'm confused about how to configure the ambient.
So I run my Laravel app with:
php artisan serve --port=8001
According to my php --ini, the conf file for xdebug is:
$ php --ini | grep xdebug
/etc/php/7.2/cli/conf.d/20-xdebug.ini
which contains:
$ cat /etc/php/7.2/cli/conf.d/20-xdebug.ini
[xdebug]
zend_extension=xdebug.so
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.idekey=default
and to debug it on gedit, I've installed this plugin. And in the text editor settings for dbgp:
Can anyone explain to me exactly how this protocol works? If I click "start to listen to debug sessions" it tries to open one on port 8001 (not 9000) which is already in use and of course it cannot open and if it's the case that I must start my PHP app in conjunction with Xdebug then how do I setup it to run it with the default Laravel command (php artisan serve)?
And, if I click Start debug in Picture related, it opens in the browser with the exact URL http://127.0.0.1/?XDEBUG_SESSION_START=default (in port 80)
Related
I use a Centos vagrant machine on which the project resides. I have enabled synced folder to the project root folder so that I can edit directly on the machine from Windows. I use VSCode or NetBeans as editor.
Now how do I debug in this situation? The code is in PHP. Local machine does not have any environments like php/apache set up. Everything is on the vagrant machine. The php script is run on vagrant while providing parameters through command line, eg -
/path/index.php folderName scriptname function_name param1 param2 param3
I already installed xdebug on vagrant. Xdebug options in php.ini
zend_extension = /usr/lib/php/modules/xdebug.so
xdebug.remote_autostart = 1
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_port=9000
Now how do i debug php scripts and see step by step what changes in VSCode or NetBeans? The php codes are cli. Tried several guides, no luck. The php files have no webpage view.
Just found that $ netstat -aon | grep 9000 returns nothing.
A simple Google search finds plenty of howtos and articles:
https://www.codewall.co.uk/debug-php-in-vscode-with-xdebug/
https://tighten.co/blog/configure-vscode-to-debug-phpunit-tests-with-xdebug
https://medium.com/#jaythedeveloper/ultimate-guide-debug-php-iis-in-visual-studio-code-using-xdebug-14fced013f22
https://jonathansblog.co.uk/remote-debugging-php-in-visual-studio-code-with-xdebug
https://www.cloudways.com/blog/php-debug-with-xdebug/
During the development on a Symfony 3.3 project I use the Symfony's internal server as seen there But I cannot figure out how to use the xdebug in order to debug it. I mean I have installed and configured xdebug via:
apt-get install php-xdebug
And I export:
export XDEBUG_CONFIG="idekey=phpstorm"
But when I put a breakpoint to my IDE and I enable the xdebug via that plugin I still get no response.
Also I have put the following settings on /etc/php/7.0/mods-available/xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable=On
xdebug.remote_autostart=On
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9021
xdebug.remote_mode=req
And I have configured both PhpStorm to listen over port 9021. But I still get the problem that I cannot make PhpStorm to listen over a breakpoint.
Do you fellows have any sort of idea how I can fix that over my ubuntu-16.04 machine?
Furthermore I have looked on these questions without any success:
Xdebug configuration with PHP fastcgi and eclipse?
Is it possible to use Xdebug with the built in PHP test server?
EDIT 1
I also tried to export the following:
export XDEBUG_CONFIG="idekey=PHPSTORM"
An configuring the Firefox plugin but still get the very same behaviour. Also keep in mind that I made the PhpStorm to listen over xdebug by pressing the button.
EDIT 2
I also put the following configuration over my PhpStorm:
Still does not work.
In the end the following steps are needed:
Put the following content into: /etc/php/7.0/mods-available/xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable=On
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9021
xdebug.remote_mode=req
Export:
export XDEBUG_CONFIG="idekey=PHPSTORM"
Then configure PhpStorm as the image shows.
Set as IDE key PHPSTORM into the Firefox plugin
Enable xdebug on Firefox via pressing the button. Alternatively you can append the url with ?XDEBUG_START part
Then press the button in PhpStorm. In case you see the then press it back again.
NOTE:
In case you change xdebug settings TERMINATE the xdebug session by pressing button and pressing back again.
Furthermore in case you run composer via terminal disable PhpStorm to listen xdebug by pressing button.
I'm on Windows and I'm trying to debug a Web application (hosted with Vagrant/Homestead) using PhpStorm through XDebug. I tried many configurations but I can't get things working. The PhpStorm XDebug setup is pretty common.
This is the current xdebug configuration:
vagrant#homestead: /etc/php/7.0/cli/conf.d/20-xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable = on
xdebug.remote_connect_back = on
xdebug.idekey='PHPSTORM'
In the IDE "Start listening for PHP debug connections" it's turned on. When I attempt to start debugging a new chrome tab opens and the URL ends, for example, with ?XDEBUG_SESSION_START=16588 but the debugger doesn't run and this is what the IDE says:
Also, netstat says the port 9000 is still listening.
Any idea?
You are changing the 20-xdebug.ini file for the Command Line Interface (CLI). Instead you need to change the /etc/php/7.0/apache2/conf.d/20-xdebug.ini for the Apache settings, since you are using Chrome.
UPDATE
I'm not sure of the differences between Apache and Nginx (which may be /etc/php/7.0/fpm/conf.d/20-xdebug.ini), but here is how I got it working with a VirtualBox VM running Apache, on a Windows computer.
Settings for 20-xdebug.ini:
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=192.168.1... (your windows IP address within your network)
xdebug.remote_port=9000
xdebug.autostart=1
I can't debug Symfony 3 with Netbeans.
I performed the following steps:
1) I installed php5-xdebug on ubuntu
2) I modified the php.ini file as follows:
zend_extension="/usr/lib/php5/20121212/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.max_nesting_level=300
3) I restarted apache
4) On Netbeans I set Run Configuration->Advanced->Do not Open Web Browser
5) I installed the easy Xdebug add-on for Firefox
6) I start the application with the console command php bin/console server:start
7) I put the breakpoint on the controller action with Netbeans
8) I start debug with Netbeans
9) I go on the url http://127.0.0.1:8000/shifts/1?XDEBUG_SESSION_START=netbeans-xdebug
Q - The page will load normally and debugging does not go on the breakpoint. Where am I wrong?
thanks
In order to debug your application using the PHP's built-in server follow the following steps:
In the tab "Projects" right-click on the project you wish to debug.
In the "Categories" list choose "Run Configuration".
In the "Run As" select box choose "PhP Built-in Web Server (running on built in web server)".
Add your Hostname and Port and press "OK".
Done with NetBeans IDE 8.2
I have been using eclipse-pdt in conjunction with xdebug and apache without problems, for over one year. Things worked flawlessly and I could do all the interactive debugging I wanted from within eclipse (using my own machine as a server).
Now I switched from apache to nginx (and therefore PHP runs now not as an Apache service but as fast-cgi) and I can't find a way to configure eclipse to work nicely with xdebug. I am neither sure if the problem is with xdebug or with eclipse (or both) to be sure.
In the eclipse configuration I already changed the reference to the PHP configuration file to /etc/php5/cli/php.ini.
Attempts with php.ini version 1
With the following php.ini file
zend_extension=/usr/lib/php5/20060613/xdebug.so
I see that xdebug is working (for example if I do a var_dump() I get the xdebug version of it, not the plain PHP one)
I can't have the interactive debugging from eclipse: the browser opens up and loads the page completely with the typical URL containing ...?XDEBUG_SESSION_START=ECLIPSE_DBGP&KEY=..., but the program execution does not stop at breakpoints
In the bottom-right corner of eclipse I see a suspicious message: "Launching =put_the_name_of_my_project_here=: 57%" that alternates with the "refreshing workspace" one.
Attempts with php.ini version 2
If I use this other version of the file (which is what it worked until I switched to nginx):
zend_extension=/usr/lib/php5/20060613/xdebug.so
xdebug.remote_enable=On
xdebug.remote_autostart=On
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_mode=req
I can't access any page of my sites at all.
PS: Additional data on my machine:
- OS: GNU/Linux - Ubuntu 9.10 64 bit.
- PHP: 5.2.10-2ubuntu6.3 with Suhosin-Patch 0.9.7; Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with Xdebug v2.0.4
- Eclipse: see screenshot.
xdebug and FastCGI use the same default port (9000). Change the port of XDebug in your php.ini file like this:
xdebug.remote_port=9001
and update your IDE settings to use 9001.
What Beau said is correct (couldn't vote since I'm new!).
Generally, addging to /etc/php5/cgi/php.ini (or locate php.ini) the lines like
zend_extension = /PATH_TO/xdebug.so ## <-- NOTE the absolute path, not relational (For ex on Windows: "C:\nginx-1.9.13\php\ext\php_xdebug-2.6.0RC2-7.0-vc14-nts.dll")
xdebug.remote_enable = on
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
xdebug.remote_port = 9900 ## <-- Yours will be probly 9000 or other..
does the job.
So after the change,
./php-fastcgi stop
./php-fastcgi start
This worked for me.
Try restarting your php. Because you have php-fastcgi, restarting nginx doesn't seem to do it. When I rebooted my whole server the change took effect.
I had the same problem and solved it.
In file /etc/php5/apache2/php.ini add:
[xdebug] xdebug.remote_enable=On
xdebug.remote_autostart=off
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_mode=req
In file /etc/php5/cli/php.ini add:
zend_extension=/usr/lib/php5/20060613/xdebug.so
xdebug.remote_enable=On
xdebug.remote_autostart=off
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_mode=req
Restart Apache:
sudo service apache2 restart
Problem in solution is "xdebug.remote_autostart = on".
If you set in file config "xdebug.remote_autostart = on". This will force Xdebug to start a debug session for every request that is done on this server, without having to specify in the request that a debug session is wanted.
You need change
"xdebug.remote_autostart = off"
And restart web service.
In this example is Apache.
You can read more here: http://doc.waterproof.fr/phpedit/debugging_profiling/configuration/debugger_with_xdebug
GoodLuck!