![]() vagrant ssh -c "XDEBUG_CONFIG=\"idekey=PHPSTORM\" PHP_IDE_CONFIG=\"serverName=\" /vagrant/app/console my-app:my-command" See the example below how we usually invoke a debug session. If you want to debug a console command you have to set two environment variables. Enable debugging in your browser by using the debug helper, or adding ?XDEBUG_SESSION_START=PHPSTORM to your query string in case of an API.Starting to listen for connections (and maybe toggling “break at first line on PHP scripts”).Once your Xdebug extension is loaded and configured, debugging of your application should be as easy as: file: VagrantfileĬonfig.vm.network 'private_network', ip: '192.168.56.100' Web & API requests ![]() Every box we use has a private network in the 192.168.56.x range, making our host location predictable (192.168.56.1). Finding the correct IP address in you vagrant box can be tricky. When using the Saltstack state mentioned above, make sure that the config paths and IP addresses are matching your setup. If your Vagrant box somehow does not contain Xdebug you can use this one-line shell command to get you started (on a Debian / Ubuntu based Vagrant machine): vagrant ssh -c "sudo apt install php-xdebug & printf 'zend_extension=xdebug.so\nxdebug.remote_connect_back=0\nxdebug.remote_host=192.168.56.1\nxdebug.remote_enable=1\nxdebug.remote_port=9000\n' | sudo tee /etc/php/*/mods-available/xdebug.ini & sudo phpenmod xdebug" In any case, all you have to do is install Xdebug and assure you configuration is set to connect back to your host OS. Since Vagrant takes care of setting up a development environment for us, and we like having our infrastructure as code, this Enrise basebox makes use of a Saltstack state such as the one below to install and configure Xdebug for us: // file: debug.sls "localSourceRoot": "/home/nico/Projects/myproject"Īt Enrise, we have been using a customized Vagrant box combined with Saltstack called the Enrise Basebox for our PHP projects in the last few years. "serverSourceRoot": "/var/www/myproject", Instead you can edit the project configuration files located in your project root. Visual Studio Code does not offer an user interface for configuring your IDE settings. Path mapping in Visual Studio CodeĪfter installing the php-debug extension for Visual Studio Code, the only thing we have to adjust is the path mapping. If you ever need to manually revise these settings you can find them in File > Settings > Languages & Frameworks > PHP > Servers. This helps to configure the so-called path mappings for any new host.Īn example of a path mapping in a project is shown below: We recommend that you enable Run > Break at fist line in PHP Scripts when setting up anything for the first time. All you have to do is click the “Start listening for connections” button. Once you set up the server side, starting a debug session in PHPStorm has been made easy due to their Zero-configuration debug feature. Of course other IDE’s are cool too (always try out new stuff!), but not covered in this article or experienced by us. For everything else, we use PHPStorm as our IDE since it has both Xdebug and Zend debugger support built in.Īs an added bonus, we’ll show you how to setup Visual Studio Code as well. Some people prefer bookmarks, that’s also fine. Should consist of a Xdebug helper button in your browser when debugging a web application. ![]() You can read more about the commands and details of the inner workings of Xdebug in the Common Debugger Protocol (DBGp) docs. If the configured ip-address is listening for incoming debug connections it will respond with further commands to facilitate the debugging session.įun fact: your IDE sends simple ASCII commands whilst Xdebug responds with XML messages. When you look at it, the concept of Xdebug is actually rather simple: whenever a PHP with Xdebug is triggered to start a session, Xdebug will send a initialization packet towards the configured remote_connect_back ip-address in the configuration. It mostly boils down to the same things over and over again, albeit in different scenario’s. This is because debugging actually isn’t that hard to configure and use once you get the hang of it. When reading the chapters below, you’ll find that there is a recurring theme of “configuring the xdebug module”, “enabling your IDE to listen on the configured port” and “initiating a debug session”. Using debuggers in PHP is probably no unfamiliar territory for us developers, but do you know how to set-up Xdebug for your CLI script? Or perhaps you are experimenting with containers and resorted back to using the good old `dd()` or `var_dump()` because the extra twist in the Docker network made your old Xdebug configuration ineffective? No worries: We’ve hooked you up with a small handbook you can use in the most common PHP debugging situations this year.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |