Debugging multiple PHP projects with VS Code and Laragon

Laragon is a great solution for developing PHP, and especially Laravel, projects on Windows.
It bundles together Apache, PHP, MySql and automatic host resolution based on folder names.
It's great...
Until...
You try and debug in VS Code using XDebug when multiple sites on your local machine are hit in quick succession resulting in multiple connections from apache being opened against port 9000 on your VS Code instance at the same time.

This manifests itself in VS Code by not hitting any breakpoints and just showing "Request 1" and "Request 2", or similar, in the debug call stack.

In my environment, I have a main project containing middleware that does a security check against a second project before hitting my main action in my controller. Both PHP instances fire off their XDebug connections on port 9000, as xdebug.remote_autostart=1 in the PHP ini file.

Normally this is fine as only one project is practically running at once, but the middleware causes the two connections to open pretty much simultaneously and the PHP XDebug extension in VS Code simply can't handle this yet.

There are a few solutions to this.

If you only want to debug one project at a time, even it multiple sites get hit, then you can use the .htaccess file in the Laravel "public" folder, and add an entry to modify the XDebug configuration such that it does not auto start:
php_value xdebug.remote_autostart = 1

Alternatively you can allocate different listening ports per project, allowing you to have multiple instances of VS Code open, each listening on a different port and servicing the XDebug connections independently:
php_value xdebug.remote_port = 9001
Make sure of course that your VS Code launch.json's port matches the one you've modified in the .htaccess file.

Comments

Popular posts from this blog

Enabling SNMP on an ASUS RT-N66U

Realtek HD Audio speakers and headphones with separate volume

Reformatting a php.ini file with Sublime Text 3 for use with Ansible