Configure Xdebug + PHPstorm on wsl2
First of all we need wsl2 ip address. To find out what’s the ip open windows powershell and run ipconfig
Under the Ethernet adapter vEthernet (WSL) look for the IPv4 Address
Go to wsl2 and open your php.ini
e.g sudo nano /etc/php/7.x/apache2/php.ini
And paste these configurations

zend_extension=”xdebug.so”
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.client_host=paste-wsl-ip-address
xdebug.client_port=9001
xdebug.mode=debug,develop,profile
xdebug.cli_color=1
xdebug.start_with_request=trigger
xdebug.log_level=3
xdebug.idekey=PHPSTORM
xdebug.discover_client_host=false
xdebug.max_nesting_level=256
xdebug.log = /var/www/html/xdebug.log
xdebug.profiler_enable=On
Note: These settings works for xdebug 3. If you are on xdebug 2 then use xdebug.remote_host and xdebug.remote_port instead
And restart your webserver
PHPstorm settings
Press ctrl+alt+s
to open the settings tab look for PHP
menu item in the left and set the CLI Interpreter
Cick in the the three dots add new interpreter from WSL
Expand PHP
menu item open Debug
and set Debug port
to 9001
Click also Break at first line in PHP scripts
Close the settings tab and click to start listening for connections

Open your browser and load your local site
Now your phpstorm should listen for the connections and you are ready to debug