- SSH into your homestead machine:
homestead ssh
-
cd
into the project directory -
Enable Xdebug:
xon
- Locate the xdebug.ini file that is loaded:
php --ini | grep 'xdebug'
My output shows the ini file at /etc/php/7.1/cli/conf.d/20-xdebug.ini
- Find your guest machine's gateway. This will be the IP Address that your guest machine can use to communicate with your host machine.
netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10
The output I see on my Homestead machine is 10.0.2.2
- Configure Xdebug to use the gateway as the
xdebug.remote_host
value:
sudo vim /etc/php/7.1/cli/conf.d/20-xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host=10.0.2.2
- Restart the PHP-FPM service
sudo service php7.1-fpm restart
- Install the PHP Debug plugin.
- Open the debug panel.
- Click on the "config" button (the cogwheel) and select PHP.
- Modify the default
launch.json
file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Listen for XDebug on Homestead",
"type": "php",
"request": "launch",
"serverSourceRoot": "/home/vagrant/Code/tighten-app-homestead",
"localSourceRoot": "/Users/jose/Code/tighten-app-homestead",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
Add a new configuration object (as shown above) that is the same as Listen for Xdebug
, but add the key/values for serverSourceRoot
and localSourceRoot
.
serverSourceRoot
is the absolute path to your project root as though you were logged into your Homestead machine.
localSourceRoot
is the absolute path to your project root on your local machine.
-
Select "Listen for XDebug on Homestead" on the debug drop-down menu.
-
Start Debugging by clicking on the green arrow button.
You're now ready to run your test from within your Homestead machine:
phpunit --filter some_test_name