PHP

From bibbleWiki
Jump to navigation Jump to search

Setting up VS Code

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