DEV Community

Sahil kashyap
Sahil kashyap

Posted on

Install xdebug with laravel in vscode ubuntu 20.04 with different version of php

Different php version has different xdebug.

follow xdebug installtion step according to php version setuped in your machine

php7.4 -v
php -v
Enter fullscreen mode Exit fullscreen mode

php7.4 version and php8 version details

this will return the php version, if xdebug is configured it will show , if not let's install it

let's install xdebug

sudo apt install php7.4-xdebug
sudo apt install php-xdebug
Enter fullscreen mode Exit fullscreen mode
php7.4 --ini
php --ini
Enter fullscreen mode Exit fullscreen mode

php ini details

look for

/etc/php/7.4/mods-available/xdebug.ini
/etc/php/8.0/mods-available/xdebug.ini

and add this to /etc/php/7.4/mods-available/xdebug.ini

; zend_extension=xdebug.so
zend_extension=/usr/lib/php/20190902/xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9003
Enter fullscreen mode Exit fullscreen mode

and add this to /etc/php/8.0/mods-available/xdebug.ini
for php8.0

; zend_extension=xdebug.so
zend_extension=/usr/lib/php/20200930/xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9003
Enter fullscreen mode Exit fullscreen mode

now type in

php7.4 -v
php -v
Enter fullscreen mode Exit fullscreen mode

you should see xdebug string returned in output

Note if you are confused about which php version is needed for which xdebug

to check which xdebug.so files are available use locate, if locate not availbe use this cmd to install it

sudo apt install mlocate
locate xdebug.so
simply paste the details you recieved from

php7.4 -i
php -i
Enter fullscreen mode Exit fullscreen mode

here https://xdebug.org/wizard
paste php info in xdebug wizad

now go to vscode

PHP Debug extension
by Felix Becker

now open the laravel project in vscode

ctrl+shift+D

for opening debug config
generate the launch.json
save the file similar to launch.json i shared here

click me launch.json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 0,
            "runtimeArgs": [
                "-dxdebug.start_with_request=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug,develop",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },
        {
            "name": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                // "-dxdebug.mode=debug",
                // "-dxdebug.start_with_request=yes",
                "-S",
                "localhost:8000",
                "-t",
                "public"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9003,
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        },
        {
            "name": "php7.4Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeExecutable": "php7.4",
            "runtimeArgs": [
                // "-dxdebug.mode=debug",
                // "-dxdebug.start_with_request=yes",
                "-S",
                "localhost:8000",
                "-t",
                "public"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9003,
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

"runtimeExecutable": "php7.4", //should use php7.4 version
            "runtimeArgs": [
                // "-dxdebug.mode=debug",
                // "-dxdebug.start_with_request=yes",
                "-S",
                "localhost:8000", //similar to php7.4 artisan server
                "-t",
                "public" //should server this folder
            ],
Enter fullscreen mode Exit fullscreen mode

get the debugging started with xdebug on vscode

select the debug config

click on green play button your out will look something like this
clck the debug button to check values

Latest comments (1)

Collapse
 
leslieeeee profile image
Leslie

Have you tried ServBay.dev?
It's a much easier tool for PHP developers, providing a user-friendly experience, especially for beginners. It supports all versions of PHP, MariaDB, PostgreSQL, as well as Redis and Memcached. You can run multiple PHP versions simultaneously and switch between them effortlessly. It also offers easy updates without the need to configure environment variables. This tool has greatly simplified my PHP development and is definitely worth trying!