PHP

From bibbleWiki
Revision as of 00:21, 12 March 2026 by Iwiseman (talk | contribs)
Jump to navigation Jump to search

Setting up VS Code

Revisited With WSL

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

Create a launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for Xdebug",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "pathMappings": {
        "/": "${workspaceFolder}"
      }
    }
  ]
}

Install extension Php Debug by Xdebug

Running in VS Code

For me I simply pressed F5 to run the launch.json and ran the code with

php -S localhost:1701

Extensions

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

Debugger

Had a bit of grief tracking this down but found these steps worked for me

Step One

sudo apt install php-xdebug

Step Two - Edit xdebug.ini

sudo vi /etc/php/7.4/mods-available/xdebug.ini

Add to the end

zend_extension=/usr/lib/php/20190902/xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9000

Step 3 - Create a launch

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
}

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