Xdebug nightmare

I also usually have problems with Xdebug when updating LocalWP and/or PHPStorm.

This time, what happening is that I have a project where the Xdebug kept working with LocalWP Version 7.2.1+6433 and PhpStorm 2023.2.2 and Windows 11

However, on new projects, doing the exact same setup, the Xdebug wasn’t working.

So, after spending a few hours on it, what worked for me was the following:

1 - Close PHPStorm

2 - In your project, remove the .idea folder from the public folder if you already have it there

3 - In your php.ini.hbs files inside the conf folder set up the Xdebug according to the version your site is using, to discover which version, click on the details link next to the PHP version on the LocalWP UI

V2.X php.ini.hbs setup:

xdebug.remote_enable=1
xdebug.remote_connect_back=Off
xdebug.remote_port="9000"
xdebug.profiler_enable=0
xdebug.remote_autostart=1

V3.X php.ini.hbs setup:

xdebug.mode=debug
xdebug.client_port="9000"
xdebug.start_with_request=yes
xdebug.discover_client_host=yes

4 - Initialize the PHPStorm again and re-open the public folder of your project to create a new .idea folder there

5 - Go to Settings > PHP > Debug and disable the following options: Force break at first line when no path mapping specified and Force break at first line when a script is outside the project

6 - DON’T USE the LocalWP add-on to add the Xdebug settings file because it is preventing the Xdebug from working somehow.

7 - Open the file /public/wp-load.php and add a breakpoint on line 20 where we have a condition to check if the ‘ABSPATH’ const is defined.

8 - Click on the Start Listening for PHP Debug Connections button in the PHPStorm toolbar.

9 - Open the home of your site and a new popup should be displayed in the PHPStorm asking you to accept Incoming Connection From Xdebug - check the attached screenshot for reference. Select the public folder in the popup, then click on Accept, and the Xdebug should start to work.

It’s that! These steps helped me enable Xdebug for new projects, hope it helps others in the same situation.

7 Likes