I have Ubuntu 18.04 and a fresh installation of Laravel 8. I want to use Xdebug together with Sail. I followed the instructions as follows:
Added SAIL_XDEBUG_MODE=develop,debug to env
Run sail build --no-cache and sail up -d
Run docker inspect -f {{range.NetworkSettings.Networks}}{{.Gateway}}{{end}} <container-name> to get the IP of my docker container
Added SAIL_XDEBUG_CONFIG="client_host=172.19.2.1" to env (IP from step 3)
Next I continued with the instruction from PhpStorm for debugging:
Validated that Xdebug is active by sail php -v.
Enabled listening to debug connection in PhpStorm
Set a breakpoint and also enabled Break at first line in PHP scripts
Installed Xdebug Helper browser extension for Chrome
Clicked on debug in extension (bug is now green)
Refresh page, page builds very slowly, but loads completely (which should not be the case, it should hang on a breakpoint)
If I switch to PhpStorm, then no dialog pops up. However, according to the instructions, there should be some instructions.
Reload the page in the browser and return to PhpStorm. In the Incoming
Connection From dialog, select the path mappings so
that PhpStorm can map the remote files on the web server to the local
files in your project.
Hera are my debug settings:
What am I missing?
Thanks to the helps of #LazyOne I got it working. I just had to skip step 3 & 4 in my instructions.
Or in other words, I had to follow the instructions of https://laravel.com/docs/8.x/sail#debugging-with-xdebug but ignore the Linux Host IP Configuration section, although I am on Linux. Looks like this section is not appropriate for Ubuntu?
Related
So the last version of Sails makes it very easy to use Xdebug. Basically just had to define SAIL_XDEBUG_MODE in the .env file, configure path mapping in PhpStorm, activate listening and all was set - it works perfectly from the browser.
Now, how should I go if I want Xdebug to activate when I'm using the command line? Like when using artisan commands for seeding, or even better when using custom artisan commands created to run scripts to update some data... I can't find any arguments to add to my sail artisan myOwnCommand that would tell Xdebug it has to activate.
I'm working on Windows 11 with WSL2.
Thanks ahead!
Thanks to Derick's suggestion, I found out a solution. Prepending a sail call with anything wouldn't help, since sail calls scripts in the docker container, and your environment variable wouldn't be set there. But since it was just about setting an environment variable, it can be easily done in docker-compose file.
I just had to add PHP_IDE_CONFIG: 'serverName=0.0.0.0' in the environment section of my Laravel service. Of course replace 0.0.0.0 with your own server name. Then, instead of running sail artisan test or sail artisan my:command you replace artisan with debug, as stated in the docs.
Now you can use command debug to run with Xdebug (ex. sail debug myOwnCommand).
Here is documentation: https://laravel.com/docs/9.x/sail#xdebug-cli-usage
At work, we use dockers to run our servers, and we work with PhpStorm and Xdebug. I want to use Xdebug at home using XAMPP, but I'm not sure how to set it up.
Usually, at work, when I want to debug stuff, I add xdebug_break(); somewhere near the offending code line, turn on "Start listening for PHP Debug Connections", and then it would stop at that point, waiting for me to manually continue. I want it to work like that at home, too.
What I did so far:
I installed Xdebug and checked phpinfo(); to make sure it's actually installed properly:
I updated php.ini and restarted the server:
I made sure the debug port is set to 9000, which is the default (hence why I didn't include it in the php.ini file)
Now, nothing happens when I go to the page with the xdebug_break();. What do I need to do to make it work?
In Laravel Homestead, I've been able to use Xdebug for unit tests, feature tests, poking around in the browser, etc.
But it hangs when I try to use Xdebug for Dusk (tests in tests/Browser folder).
I thought these questions might help, but I still haven't gotten it working:
debugging laravel artisan from PHPStorm with homestead
Xdebug laravel artisan commands
I've tried various approaches, including:
export XDEBUG_CONFIG="idekey=netbeans-xdebug remote_connect_back=0 remote_host=10.0.2.2"
php artisan dusk
and
export XDEBUG_CONFIG="idekey=netbeans-xdebug remote_host=10.0.2.2"
php -dxdebug.remote_autostart=on -dxdebug.remote_connect_back=off -dxdebug.remote_host=10.0.2.2 artisan dusk
and more.
I've enabled the "Stop at First Line" debugging option in Netbeans, and Netbeans does successfully stop at the first executable PHP line in the artisan file.
Therefore I think export XDEBUG_CONFIG="idekey=netbeans-xdebug remote_connect_back=0 remote_host=10.0.2.2" is correctly set up.
But after I click the "play" button to allow the code to continue, Netbeans just says "netbeans-xdebug running" in the bottom right while the console just hangs with a cursor flashing under this line: php artisan dusk tests/Browser/ExampleTest.php
How do I need to change my usage of Xdebug for getting it to work in Dusk too?
It doesn't work because Dusk executes the actual PHPUnit test in a separate process, so it doesn't know about XDEBUG_CONFIG.
In principle, Dusk tests still work when you execute them directly (phpunit tests/Browser/ExampleTest.php). The main feature of php artisan dusk are custom .env.dusk[.local] files.
If you don't require that, you can try calling them directly. Then Xdebug should behave the same way it does with all your other PHPUnit tests.
As in my answer here, there is an option of running php -dxdebug.remote_enable=1 -dxdebug.remote_host=10.0.2.2 -dxdebug.remote_port=9000 -dxdebug.remote_handler=dbgp artisan my:command
You can also add those parameters to xdebug.ini like so:
zend_extension_ts = "./php/ext/php_xdebug<-version-number>.dll"
xdebug.remote_enable=1
xdebug.remote_host=10.0.2.2
; Port number must match debugger port number in NetBeans IDE Tools > Options > PHP
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.idekey=netbeans-xdebug (although I think it should work without this too)
Try removing break at first line option. Also try running debug directly from console with those options. And finally check that the correct port is set to listen in NetBeans and xdebug since that could cause problems too.
I regularly use xDebug on my projects without any problems although I have one project which I've started developing a Magento Module on and xDebug is not working on it. It does still work on other projects though.
I can see xDebug in my phpinfo.php file.
xDebug seems to be running on port 9000.
$ sudo netstat -tulpn | grep :9000
tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN 17261/java
I'm using this Chrome extension to start listening to start using xDebug.
I don't understand why xDebug will work on other projects but not this one, any advice very much appreciated.
UPDATE
Interestingly when I added the URL of the project I'm trying debug to the PHPStorm settings of another project which xDebug works fine on, by going File -> Settings -> Languages & Frameworks -> PHP Servers, xDebug kind of works. Both projects are Magento Apps so have same directory/file structure.
With this setting Xdebug breaks in that project but with the warning.
The script '/var/www/example/index.php' is outside the project.
If I try adding this setting to the project I'm trying to debug, nothing happens.
I've read other questions regarding this topic. The listed solutions haven't worked.
Installed:
XAMPP 1.7.7
Netbeans 7.1.1
XDebug 2.1.4
phpinfo() shows that Xdebug is installed with all the correct parameters:
zend_extension = C:\xampp\php\ext\php_xdebug-2.1.4-5.3-vc9.dll
xdebug.remote_enable = on
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "localhost"
xdebug.remote_port = 9000
However, when I start a Netbeans debug session, it cycles for awhile with no effect. When I stop it, I get the Info box informing me that "No connection from xdebug was detected with in nn seconds. The reasons could be that xdebug is not installed or not properly configured. (their emphasis).
As far as I can tell, I configured everything correctly, restarted the Apache server and it still doesn't work. I'm at a total loss on how to proceed. Any help is appreciated.
Can you believe it!? After spending literally HOURS researching this problem, I finally found the cause which I can only classify as a bug. Now, how do I report a bug? That's the next question.
Here's a summary:
create PHP project and setup NetBeans project site root to subfolder.
(In order to not register for Apache new test site for any new task I
put every new task into subfolder under my local test domain, e.g.
http://test.my/project3/ ). NetBeans will not start debugging session
automatically in this case. You will see a ‘waiting for connection’
message from the image below. Do not worry. Left it as it is. Go to
your browser. I use FireFox 4. And call the script you wish to debug
with additional parameter, e.g.
http://test.my/project3/index.php?XDEBUG_SESSION_START=netbeans-xdebug
When you return to NetBeans you will see that connection with xdebug
is established successfully. To stop XDebug session manually call any
script from the same subdirectory with this parameter
?XDEBUG_SESSION_STOP_NO_EXEC=netbeans-xdebug
The complete solution can be found on my newest hero's blog NetBeans 7.0 for PHP Waiting for Connection to XDebug
Edit: Know what I just discovered? I removed index.php as the index file of my run configuration. Works like a charm without having to manually insert the xdebug section of the url.
I just ran into this with Netbeans 8 and while your answer worked around my problem I think I found the solution that will fix it forever.
Project Properties => Run Configuration => Advanced ...
Ensure that the following entry is selected
Debug URL: 'Default: YOUR URL'
Mine was set to "Do Not Open Web Browser" .....
Now it works as it used to work many months ago :)
I am a .Net programmer and very new to PHP. Recently I was trying to host an open source PHP application on my machine(Windows). After the Struggle for 5-6 days I will list the steps which worked for me.
I uninstalled every previous installations of XAMPP and NetBeans and proceeded with fresh installations.
This might not be the solution for everyone but it worked for me and I hope it helps someone.
install XAMPP
install netbeans for PHP.
Open IIS and stop it. It is running on port 80 by default.(I am running XAMPP on port 80 i.e. default, Running on other port might need additional configuration settings)
Open XAMPP control panel and start Apache. If port 80 is free no problem should arise.
Open localhost in browser in should display XAMPP home page.
open phpinfo() link on the left pane and copy all the contents on page. Go to: http://xdebug.org/wizard.php and paste all the content in TextBox and click Analyze my phpinfo output. It will diplay you the Xdebug file suitable for your configuration.
Download the given Xdebug dll and copy it in C:\xampp\php\ext (Xampp being the default Xampp installation directory)
Goto XAMPP control panel, click on Config button in front of Apache and select php.in,
Find line similar or exacly like,
;zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
(Semicolon means it is commented)
Remove the semicolon and replace the path with the path of dll you just copied like:
zend_extension = "C:\xampp\php\ext\php_xdebug-2.3.2-5.4-vc9.dll"
Similarly find lines
;xdebug.remote_enable = 0 ;xdebug.remote_handler = "dbgp"
remove semicolons in front of both lines and make remote_enable = 1
xdebug.remote_enable = 1 xdebug.remote_handler = "dbgp"
Restart Apache server.
Copy your website code under C:/XAMPP/htdocs/(your_website)/ that means your index.php should be at C:/XAMPP/htdocs/(your_website)/index.php
Open Netbeans select New project -> PHP -> PHP project from existing source and select the folder you just copied in htdocs folder. Set it to run on Local web server.
Set a breakpoint on first line of index.php and debug.
That's it.
Additional settings were suggested on various different posts but above mentioned steps worked perfectly for me.
I think what you might be missing is
xdebug.idekey=netbeans-xdebug
this is the settings I use in my php.ini
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1 # Not safe for production servers
xdebug.remote_port=9000
xdebug.idekey=netbeans-xdebug
xdebug.remote_autostart=false
Read the installation of XAMPP 1.7.7 & Netbeans 7.1 with edditing
the php.ini file as suggested:
http://netbeans.org/kb/docs/php/configure-php-environment-windows.html
Create your PHP project in the local XAMPP directory, c:\xammp\htdocs\*yourproject*
Debug the index.php, you will see that your browser will start with additional parameters:
http://*yourproject*/index.php?XDEBUG_SESSION_START=netbeans-xdebug
Go to your Netbeans, your debugger will be started.