Skip to content

Instantly share code, notes, and snippets.

@dipenparmar12
Last active May 18, 2020 16:20
Show Gist options
  • Save dipenparmar12/53944ac112146f8fa472f9b3fe8cd572 to your computer and use it in GitHub Desktop.
Save dipenparmar12/53944ac112146f8fa472f9b3fe8cd572 to your computer and use it in GitHub Desktop.
Step by step installation Instructions, How to setup Xdebug in Linux environment, using VsCode

How to use PHP Xdebug using Vscode

PHP

Update the system packages to the latest versions:
  • Update linux, software repository

    sudo apt-add-repository ppa:ondrej/php

  • Update the system packages

    sudo apt update

    sudo apt upgrade

Install PHP
  • Skip this step if you have installed workig PHP interpreter

Run the following command to install PHP and all required PHP modules:

sudo apt install php7.2-common php7.2-cli

sudo apt install php7.2-gd php7.2-mysql

sudo apt install php7.2-intl php7.2-mbstring

sudo apt install php7.2-bcmath php7.2-imap

sudo apt install php7.2-xml php7.2-zip

sudo apt install php-soap

sudo apt install php-curl

XDebug

You will need to make sure your operating system meets the requirements, Xdebug and PHP version compatibility XDebug compatibility

installation and Integrate Xdebug with the PHP interpreter

sudo apt install php-xdebug

Check Xdebug is successfuly included in module list by following commad

php -m

You will see something like this

[PHP Modules]
calendar
date
mbstring
.
..
...
[Zend Modules]
Xdebug --> Note: This is what we want in modlue list
Zend OPcache
Modify the PHP Configurations by editing php.ini

To find correct path of php.ini

sudo php --ini

You will see something like this

Configuration File (php.ini) Path: /etc/php/7.4/cli
Loaded Configuration File:         /etc/php/7.4/cli/php.ini
Scan for additional .ini files in: /etc/php/7.4/cli/conf.d
Additional .ini files parsed:      /etc/php/7.4/cli/conf.d/10-opcache.ini,
/etc/php/7.4/cli/conf.d/10-pdo.ini,
..
...

Copy line Loaded Configuration File: /etc/php/7.4/cli/php.ini

Using Nano editor, open php.ini

sudo nano /etc/php/7.4/cli/php.ini

Add following lines at end of php.ini file

[Xdebug]
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000

To save changes Ctrl+x, y, Enter after editing to save & Restart your system.

Verify Xdebug installation by doing any of the following:
  • In the command line, run the following command:

    php --version

    The output should list Xdebug among the installed extensions:

    PHP 7.4.6 (cli) (built: May 14 2020 10:03:35) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
      with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies
      with Xdebug v2.9.3, Copyright (c) 2002-2020, by Derick Rethans
    

    When you see with Xdebug v2.9.3 line in php --versioncommand that means you have succufuly installed and configuraed Xdebug in your php Configuration.

VS Code Configuration

PHP Debug Adapter for Visual Studio Code

Extention

Install the extension: Press F1, type ext install php-debug.

  • In your project, go to the debugger and hit the little gear icon and choose PHP. A new launch configuration will be created for you with two configurations:

    • Listen for XDebug This setting will simply start listening on the specified port (by default 9000) for XDebug. If you configured XDebug like recommended above, everytime you make a request with a browser to your webserver or launch a CLI script XDebug will connect and you can stop on breakpoints, exceptions etc.

    • Launch currently open script This setting is an example of CLI debugging. It will launch the currently opened script as a CLI, show all stdout/stderr output in the debug console and end the debug session once the script exits.

For more details click here

Features

  • Line breakpoints
  • Conditional breakpoints
  • Function breakpoints
  • Step over, step in, step out
  • Break on entry
  • Breaking on uncaught exceptions and errors / warnings / notices
  • Multiple, parallel requests
  • Stack traces, scope variables, superglobals, user defined constants
  • Arrays & objects (including classname, private and static properties)
  • Debug console
  • Watches
  • Run as CLI
  • Run without debugging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment