DEV Community

vuong ⛈️
vuong ⛈️

Posted on

Debugging PHP application in Vagrant by Xdebug & VSCode


  • Follow all steps to set up for VSCode.
  • Follow 1, 2, 5 to set up for a server (required for any debugger tool).


  • PHP >=5.3 in CentOS 6.x
  • Your PHP project is running in Vagrant
  • The Vagrant instance in this tutorial running on CentOS 6
  • Host machine in this tutorial is Windows 10
  • VSCode, of course!

Install & configuration Xdebug in Vagrant

  • Access root permission by command
sudo -i
Enter fullscreen mode Exit fullscreen mode
  • Run below commands in Vagrant
rpm -Uvh
yum install --enablerepo=remi --enablerepo=remi-php56 php-pear php-devel -y
pecl install xdebug
service httpd restart
Enter fullscreen mode Exit fullscreen mode
  • Add configurations for XDebug in the end of /etc/php.ini file
; Host machine of Vagrant instance

; Another xdebug configuration (in php.ini) set to profiling source code (optional). [Read more](

; xdebug.profiler_enable_trigger=1
; xdebug.profiler_output_dir=/vagrant/profiler
Enter fullscreen mode Exit fullscreen mode
  • Open .vscode/launch.json or (button setting for debug mode in VSCode), configure it like this below:
    "version": "0.2.0",
    "configurations": [
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "serverSourceRoot": "/var/www/your_website",
            "localSourceRoot": "${workspaceRoot}",
            "port": 9000,
            "log": true
Enter fullscreen mode Exit fullscreen mode

Install PHP Debug for Visual Studio Code

  • Search the extension as name PHP Debug, install it

Problem with Firewall

There may be a problem with the OS firewall.

Solve: In Windows, access Control Panel\System and Security\Windows Firewall >> Choose to Allow an app or feature through Windows Firewall > Check both options (Private/Public network) for VSCode (or PhpStorm).

Relate topics

Configuring Visual Studio Code for PHP Development

Top comments (0)