Install xdebug with laravel in vscode ubuntu 20.04 with different version of php
Sahil kashyap
Posted on July 5, 2021
Different php version has different xdebug.
follow xdebug installtion step according to php version setuped in your machine
php7.4 -v
php -v
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
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
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"
}
}
]
}
"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
click on green play button your out will look something like this
Posted on July 5, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
July 5, 2021