[Tutorial] How to add Xdebug to Laragon


  • administrators
    | 94256 points

    You can add Xdebug to Laragon easily.
    Method 1: Using phpinfo() & Xdebug Wizard

    1. Copy phpinfo() content:
      http://localhost/?q=info

    2. Paste the copied data to the form in the Xdebug Wizard page
      https://xdebug.org/wizard.php

    3. 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.


  • | 3729 points

    @leokhoa I found I also needed to add xdebug.remote_enable=1 to the php.ini file. Otherwise, those steps worked great.


  • | 246 points

    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:
    http://localhost:8080/operators.php
    No luck.
    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

    Solution found:
    Add the following 3 lines to php.ini
    [xdebug]
    xdebug.remote_enable= 1
    xdebug.remote_autostart = 1


  • | 3254 points

    You need xdebug.remote_enable=1 if 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 remote_autostart. Setting xdebug.remote_autostart=1 will force xDebug to always attempt to connect to the remove client, regardless if the XDEBUG_SESSION is properly set. I actually don't believe this should be recommended for all. Most users should leave this off and use the XDEBUG_SESSION cookie 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 )


  • | 3254 points

    Here are the plugins/extensions from https://xdebug.org/docs/remote if interested...

    ...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.


  • | 246 points

    @pfaciana thank you - this is way over my head at the moment, but it gives me something to look into.


  • | 825 points

    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?


  • | 3729 points

    @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


  • | 246 points

    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.


  • | 3729 points

    @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)


  • | 246 points

    @mnelson4 Thank you, it was a boneheaded mistake on my part - sorry. Reinstalled using PHP Tools for VS Code and it worked.


  • administrators
    | 94256 points

    @mnelson4 , @danieliser: I've released Laragon 3.5 which works well with xdebug in PHP 7.2+.


  • | 246 points

    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!


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.