To be able to debug through Magento 2’s setup scripts i.e. InstallSchema, UpgradeSchema, InstallData, UpgradeData, from PHPSTORM and XDEBUG, follow the steps:

To setup debugger for php bin/magento cli

1. Make sure your xdebug is configured to accept external connection in storm.
2. Run any M2 cli command and when prompted click accept on the external connection dialog.
3. Click Run > Edit Configurations.
4. Setup a new ‘PHP Remote Debug’ configuration, take a note on server. In my case, it’s the vagrant IP, and set ‘IDE key session’ as phpstorm.
5. Setup a breakpoint on InstallSchema.php or InstallData.php etc.
6. Map your class path from Preference > Language & Frameworks > PHP > Servers, you need to select the host with the IP i.e. 10.0.2.15 found in step 4.
7. Click on the ‘BUG’ icon on your storm at the right top corner and run in terminal the following:

XDEBUG_CONFIG=idekey=phpstorm php bin/magento setup:upgrade

 

That should do it!

Cheers!