PHP
Setting up VS Code
Install PHP and XDebug
First install the software. This was done in the WSL
sudo apt install -y php8.5 php8.5-cli php8.5-common php8.5-mbstring php8.5-xml php8.5-curl php8.5-mysql
sudo apt install php-xdebug
Check your php now has Debug. You should see Xdebug listed
php -v
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.5.3, Copyright (c) Zend Technologies
with Xdebug v3.5.0, Copyright (c) 2002-2025, by Derick Rethans
with Zend OPcache v8.5.3, Copyright (c), by Zend Technologies
Change Your Xdebug.ini
Find you wsl ip with
hostname -I
172.28.58.213
Find your xdebug.ini
php -i | grep 'xdebug.ini'
/etc/php/8.5/cli/conf.d/20-xdebug.ini,
Now amend your xdebug.ini to have this and remember to use your ip
zend_extension=xdebug.so
xdebug.mode = develop,debug
#xdebug.start_with_request = trigger
xdebug.start_with_request = yes
xdebug.client_port = 9003
xdebug.client_host = 172.28.58.213
Set up VS Code
Install extension Php Debug by Xdebug and create a launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
}
]
}
Note the robot wanted me to put this in the launch.json file and it stopped it working
"pathMappings": {
"/": "${workspaceFolder}"
}
Running in VS Code
For me I simply pressed F5 to run the launch.json and ran the code with
php -S localhost:1701
You need to go to you browser and access you php application. Mine starts with index.php to http://localhost:1701. You must press F5 before starting code because the code needs to find the debugger when starting. For me I saw this when working
[Thu Mar 12 13:29:40 2026] PHP 8.5.3 Development Server (http://localhost:1701) started
[Thu Mar 12 13:29:47 2026] 127.0.0.1:37794 Accepted
[Thu Mar 12 13:29:47 2026] 127.0.0.1:37794 [200]: GET /
[Thu Mar 12 13:29:47 2026] 127.0.0.1:37794 Closing
[Thu Mar 12 13:29:47 2026] 127.0.0.1:37808 Accepted
And this when failed
[Thu Mar 12 13:26:38 2026] PHP 8.5.3 Development Server (http://localhost:1701) started
[Thu Mar 12 13:26:51 2026] 127.0.0.1:39096 Accepted
[Thu Mar 12 13:26:51 2026] Xdebug: [Step Debug] Could not connect to debugging client. Tried: 172.28.58.213:9003 (through xdebug.client_host/xdebug.client_port).
[Thu Mar 12 13:26:51 2026] 127.0.0.1:39096 [200]: GET /
[Thu Mar 12 13:26:51 2026] 127.0.0.1:39096 Closing
[Thu Mar 12 13:26:51 2026] 127.0.0.1:39106 Accepted
Other Stuff I installed
We need to install
sudo apt install php-cli composer php-xml
You will need to set up php-cs-fixer first. Extensions suggested are
- PHP Intelephense
- PHP Getters & Setters
- PHP debug
- PHP CS Fixer
- Twig Language 2
- SQLTools
Creating Project With Composer
To create a project you need to run the following. The only tricky bit is the name where they want vendor/name e.g. bibble/test
composer init