Xdebug, DDEV, WSL2 and corporate network restrictions
Since a few months, I have a new job at a new company, which also means a new working setup: I work in a corporate group with standardized IT guidelines, while being the only one web developer. In other words: I'm working on a Windows machine, where I do not have admin permissions and the network traffic is regulated.
But that's fine. Setting up DDEV inside the WSL2 environment was pretty easy. - Except one thing: Xdebug - With all the ports blocked, Xdebug (running inside DDEV, running inside WSL2) was not able to talk to my IDE, which directly runs on the Windows host system. Here is how I solved it:
1) Ask IT department to open ports #
I asked the IT department to open the ports 9000 and 9003 on my machine to allow incoming traffic. I think, port 9003 would have been enough. But PhpStorm has listed both of them and so the IT guy decided to open both of them.
2) Find your computer's IP address #
I'm pretty sure, there are multiple ways to find your IP address. But I don't want to click multiple times through menus
and settings. So my simple way to find the IP address is to open a command line in Windows and type ipconfig
3a) Add configuration file to DDEV #
The third step was to add the file .ddev/php/xdebug_wsl.ini
with content xdebug.client_host=YOUR_IP_ADDRESS
and restart
DDEV. Of course, you need to add your actual IP address instead of the placeholder string. Additionally, I recommend to add this file to .gitignore
because your IP address will change.
3b) Global DDEV command #
The solution with the above PHP INI file works but has several disadvantages:
- You need this file in each of your DDEV projects
- The IP address will change, and you have to decide if you want to add this file to your Git or not
- You have to restart your DDEV project when the IP address changes, this could even happen multiple times a day
To solve this disadvantages, I had another idea. I decided to delete the files from above from all repositories and
instead created a global DDEV command in the file ~/.ddev/commands/web/x
:
#!/usr/bin/env bash
## Description: Prepare Xdebug for usage with WSL in our corporate infrastructure. Run `ipconfig` on windows shell to find current IP address.
## Usage: x
## Example: ddev x 10.102.11.1
if [ -z "$@" ]; then
echo "IP address missing"
exit 1
fi
CONTENT="xdebug.client_host=$@"
echo $CONTENT > /etc/php/$DDEV_PHP_VERSION/cli/conf.d/xdebug_wsl.ini
echo $CONTENT > /etc/php/$DDEV_PHP_VERSION/fpm/conf.d/xdebug_wsl.ini
echo $CONTENT
enable_xdebug
To set the correct IP address for Xdebug in a project, I now have to execute two simple steps:
- run
ipconfig
in Windows to find the computer's current IP address - run
ddev x YOUR_IP_ADDRESS
in Linux to dynamically set the PHP setting and start Xdebug
The advantages of this solution are:
- No project restart needed when the IP address changes (e.g. after VPN reconnect)
- Script can be placed globally instead of required modifications in each project
- Previous: My personal Twitter Archive
- Next: <textarea> and line breaks