How to run or debug php on Visual Studio Code (VSCode)



PHP Snippet 1:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Start Server",
            "type": "shell",
            "command": "php -S localhost:8080 -t ${fileDirname}",
            "isBackground": true,
            "group": "build",
            "problemMatcher": []
        },
        {
            "label": "Run In Browser",
            "type": "shell",
            "command": "open http://localhost:8080/${fileBasename}",
            "windows": {
                "command": "explorer 'http://localhost:8080/${fileBasename}'"
            },
            "group": "build",
            "problemMatcher": []
        },
        {
            "label": "Run In Terminal",
            "type": "shell",
            "command": "php ${file}",
            "group": "none",
            "problemMatcher": []
        }
    ]
}

PHP Snippet 2:

{
    "launch": {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "php",
                "request": "launch",
                "name": "Run using PHP executable",
                "program": "${file}",
                "runtimeExecutable": "/usr/bin/php"
            }
        ]
    }
    // all your other user settings...
}

PHP Snippet 3:

sudo apt-get install php-xdebug

PHP Snippet 4:

[
    {
        "key": "ctrl+s",
        "command":"terminalCommandKeys.run",
        "when": "editorLangId == php",
        "args": {
            "cmd":"php ${file}",
            "newTerminal":true,
            "saveAllfiles": true,
            "showTerminal": true,
        }
    }
]

PHP Snippet 5:

xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9000

PHP Snippet 6:

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9000