Install xdebug with laravel in vscode ubuntu 20.04 with different version of php
Tags: laravel, ubuntu, xdebug
Published: 2021-07-05 17:44:54

###Different php version has different xdebug.
follow xdebug installtion step according to php version setuped in your machine

```
php7.4 -v
php -v
```
![php7.4 version and php8 version details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b9dkbipz4b4cwey0nt81.png)


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
```

```
php7.4 --ini
php --ini
```

![php ini details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2f4ot51b51fotkdp4d9i.png)


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
```
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
```


now type in 
```
php7.4 -v
php -v
```
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
```
here https://xdebug.org/wizard
![paste php info in xdebug wizad](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gafey69w1ll7n251iqrq.png)
##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

  {% details *click me* launch.json  %}
```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"
            }
        }
    ]
}
```
{% enddetails %}

```javascript
"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
            ],
```

get the debugging started with xdebug on vscode

![select the debug config](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hju9glpeqod6h4o5gx12.png)

click on green play button your out will look something like this
![clck the debug button to check values](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/haxmg8su7afsuwd2qwwk.png)