[Tutorial] How to add Xdebug to Laragon
You can add Xdebug to Laragon easily.
Method 1: Using phpinfo() & Xdebug Wizard
Copy phpinfo() content:
Paste the copied data to the form in the Xdebug Wizard page
Click "Analyse my phpinfo() output", and follow the instructions.
Note: Their instructions will ask for "4. Restart the webserver" but with Laragon, you just need to click Reload button.
@leokhoa I found I also needed to add
php.inifile. Otherwise, those steps worked great.
Still can't get it to work. I place a break in my php program then open it in my Chrome browser and launch it using:
I've got it working in XAMPP though.
My phpinfo reports:
This program makes use of the Zend Scripting Language Engine:
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans
Add the following 3 lines to php.ini
xdebug.remote_autostart = 1
xdebug.remote_enable=1if you plan to contact a debug client. Which I would suspect a lot of people would/should. However, it's not required, its just one feature of xDebug. You can still get a lot of value from xDebug even if it's turned off (which it is by default).
Also by off by default is
xdebug.remote_autostart=1will force xDebug to always attempt to connect to the remove client, regardless if the
XDEBUG_SESSIONis properly set. I actually don't believe this should be recommended for all. Most users should leave this off and use the
XDEBUG_SESSIONcookie instead. There are many browser plugins that can set this for you, and I should think that would be the recommended way. Remote debugging carries a large performance hit, and I've seen it cause issues in some edge cases. So I would think most people would only want that when they are actually stepping through code, and not every single time you make a request to the website. To each their own, but I felt it was important to point out just in case a reader was not familiar with what these settings do.
( Here are the all the setting if you want to read more: https://xdebug.org/docs/all_settings )
Here are the plugins/extensions from https://xdebug.org/docs/remote if interested...
- Xdebug Helper for Firefox ( https://addons.mozilla.org/en-GB/firefox/addon/xdebug-helper-for-firefox )
- Xdebug Helper for Chrome ( https://chrome.google.com/extensions/detail/eadndfjplgieldjbigjakmdgkmoaaaoc )
- Xdebug Toggler for Safari ( https://github.com/benmatselby/xdebug-toggler )
- Xdebug launcher for Opera
...You would use these as one option instead of setting
xdebug.remote_autostart=1. Or you could just set the cookie manually, or by script, etc. More information on remote debugging is on that page as well.
@pfaciana thank you - this is way over my head at the moment, but it gives me something to look into.
What is the purpose of the PHP -> Quick Settings -> xdebug option? Clicking it restarts Apache & Nginx but doesn't disable xdebug (once installed per above method).
Is it purely for notification purposes?
@danieliser kinda a good question. As I understand it, it should really toggle xdebug on and off. So it sounded great but I haven't got it to work yet. (To enable xdebug, I followed the above instructions; and to disable it, I remove the xdebug lines from my php config file, save, and restart Laragon)
You should probably start a separate topic with your question IMO
Ugh! My xdebug has stopped working in web mode, though running it with a local script works ok. It doesn't appear to be listening to the web server at all.
@Michael-Chean that's a mystery alright. You should probably create a new issue (feel free to ping me and I'll try to help)
@mnelson4 Thank you, it was a boneheaded mistake on my part - sorry. Reinstalled using PHP Tools for VS Code and it worked.
I finally gave up on doing this myself. I'm using VSCode so I was able to install PHP Tools for VS Code by Devsense which installs Xdebug and some other useful tools. So far no problems!
From the documentation on the official github page for VSCode PHP Debug extension, seems like all you need to do is to add xdebug.remote_connect_back = 1 to [Xdebug] section in php.ini. This will work for other clients too, not only VSCode with this extension. I think that vhosts are causing this problem and remote_connect_back tells the client what server address it should listen to
This worked with vscode+laragon:
"name": "Listen for XDebug",
add this to end of php ini: ----------------------------------
zend_extension = W:\laragon\bin\php\php-7.2.11-Win32-VC15-x64\ext\php_xdebug-XXXXXXXXXX.dll
xdebug.remote_enable = 1
xdebug.remote_host = localhost
xdebug.remote_port = 9000
xdebug.remote_connect_back = 1
Debugging works, but the quick settings in Laragon does not work, i think it needs to set the "xdebug.remote_enable" to false when not used?
@martinandersen3d I think you're "overthinking" it. If you have correct ext path (which you should), you only need to provide
I also use default configuration that VSCode creates and it works out of the box. My variables look like this (I also have profiler enabled by setting the debug variable XDEBUG_PROFILE - can be found in the docs)
[xdebug] xdebug.remote_enable=1 xdebug.remote_autostart=1 xdebug.profiler_enable_trigger=1 xdebug.profiler_enable=0 xdebug.profiler_output_dir=C:/_DEV/tmp/xdebug/ xdebug.profiler_output_name=callgrind.%p
Regarding the Quick Settings, make sure you have only one mention of zend_extension=php_xdebug.dll and only one dll in ext directory. If all conditions are met, Laragon will disable the line as expected.
Above works for me for PHP5.6, PHP7.1, PHP7.2, PHP7.3 with Apache/Nginx configuration, latest compatible release of xdebug and Laragon 4.0.x (currently 4.0.12)
Thanks P Mo. It works
I've created a Hotkey to toggle xDebug On/Off.
Get it here:
Overkill i guess
Have anyone tried adding xdebug to PHP 7.4 RC2 NTS? I had no sucess even tho i've followed the instructions provided my xdebug site:
- Download php_xdebug-2.8.0beta2-7.4-vc15-nts-x86_64.dll
- Move the downloaded file to C:\laragon\bin\php\php-7.4.0RC2-nts-Win32-vc15-x64\ext
- Edit C:\laragon\bin\php\php-7.4.0RC2-nts-Win32-vc15-x64\php.ini and add the line
- zend_extension = C:\laragon\bin\php\php-7.4.0RC2-nts-Win32-vc15-x64\ext\php_xdebug-2.8.0beta2-7.4-vc15-nts-x86_64.dll
- Restart the webserver
@SHJordanSLIM it's not your fault, it's not working properly with TS too .. basically I don't need to do anything for new PHP versions and xDebug integration, just copy the file, rename to php_xdebug.dll and Laragon does the rest .. it's working fine for me with PHP5.6&xDebug2.5.5 and PHP7.1/7.2/7.3&xDebug2.7.2 .. PHP7.4&xDebug2.8.0 is not working for now
To change the version of php you just have to download the version you need according to your architecture at http://windows.php.net/download/, and then leave in the php path in the example case it was C: \ laragon \ bin \ php
In the case of laragon the dll extension is done in the extensions menu because it did not give good results it was added manually in php.ini
And add the following:
zend_extension = "C: \ laragon \ bin \ php \ php-7.2.0-Win32-VC15-x64 \ ext \ php_xdebug-2.6.0beta1-7.2-vc15-x86_64.dll"
xdebug.default_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = localhost
xdebug.remote_enable = on
xdebug.remote_handler = dbgp
xdebug.remote_mode = req
xdebug.idekey = "php-vs"
xdebug.profiler_append = 0
xdebug.profiler_enable = 0
xdebug.profiler_enable_trigger = 1
Generate restart in the apache service session. Also as a reference the configuration in laragon is:
Enter https://xdebug.org/wizard.php, enter http: // localhost /? Q = info on this page you get all the code that I give you phpinfo.php
You enter this content on the Xdebuger section wizard page
And follow the instructions that indicate the result of the page.
The dll leave in C: \ laragon \ bin \ php \ php-7.2.0-Win32-VC15-x64 \ ext