Skip to content

Xdebug & PHPStorm

Max Uroda edited this page Jul 2, 2019 · 3 revisions

Xdebug & PHPStorm

Prerequisites

Before all the following steps - make sure you are using the latest version of mage2click/docker-magento-mutagen by executing bin/selfupdate and bin/selfupdate -a. Check your docker-compose.yml file and remove the following lines if they exist and restart containers by bin/restart(we have had these lines generated for phpfpm section by interactive setup on previous versions): ports: - "9001:9001"

Setup Procedure

  1. First, install the Chrome Xdebug helper. After installed, right click on the Chrome icon for it and go to Options. Under IDE Key, select PHPStorm from the list and click Save.

  2. Next, enable Xdebug in the PHP-FPM container by running: bin/setup/xdebug and bin/xdebug enable. Please note that Xdebug is disabled in phpfpm container by default to prevent performance issues, so after each bin/stop & bin/start you will need to enable it manually via bin/xdebug enable. We also recommend to enable it only before debugging, since it has an impact to TTFB when enabled and not used.

  3. Open PHPStorm > Preferences > Languages & Frameworks > PHP > Debug and set Debug Port to 9001.

  4. Open PHPStorm > Preferences > Languages & Frameworks > PHP > Servers and create a new server:

    • Set Name and Host to your domain name (ex. magento2.test)
    • Keep port set to 80
    • Check the Path Mappings box and map src to the absolute path of /var/www/html
  5. Go to Run > Edit Configurations and create a new PHP Remote Debug configuration by clicking the plus sign and selecting it. Set the Name to your domain (ex. magento2.test). Check the Filter debug connection by IDE key checkbox, select the server you just setup, and under IDE Key enter PHPSTORM. This IDE Key should match the IDE Key set by the Chrome Xdebug Helper. Then click OK to finish setting up the remote debugger in PHPStorm.

  6. Open up src/pub/index.php, and set a breakpoint near the end of the file. Go to Run > Debug 'magento2.test', and open up a web browser. Ensure the Chrome Xdebug helper is enabled by clicking on it > Debug. Navigate to your Magento store URL, and Xdebug within PHPStorm should now trigger the debugger and pause at the toggled breakpoint.

Debugging php scripts with Xdebug:

  1. Add breakpoint in your php file in PHPStorm
  2. Run bin/bash to login to php container
  3. Run the needed php script with the following prefix: XDEBUG_CONFIG="remote_enable=1 remote_port=9001 remote_host=host.docker.internal idekey=PHPSTORM" /usr/local/bin/php -f <path_to_php_script/php_script_name.php> for example to debug the bin/magento script use the folowing command XDEBUG_CONFIG="remote_enable=1 remote_port=9001 remote_host=host.docker.internal idekey=PHPSTORM" /usr/local/bin/php -f bin/magento

Feel free to contact us via chat #mutagen-sync in Slack in case you need help with configs.

Clone this wiki locally