18

Running a script in command line is something we frequently do in Magento 2. For example, when creating new module, we must run setup:upgrade command. We cannot see all the information we need to know.

I know many Magento developers choose PHPStorm as their favorite editor. How we can use PHPStorm to debug Magento 2 command lines?

asked Mar 6, 2016 at 3:12

3 Answers 3

27

I configured "PHP Remote Debug" in PHPStorm and just add XDEBUG_CONFIG before script to start debugging.

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

answered Mar 6, 2016 at 7:59
3
  • How to setup debug in local. I am running php 5.5.15 with xdebug 2.2.3 on windows 10 and xampp . Enable listening and setting in configuration but console debug run without any logs Commented Mar 6, 2016 at 18:49
  • Hope this documentation help you confluence.jetbrains.com/display/PhpStorm/… Commented Mar 6, 2016 at 19:20
  • 1
    it works perfectly! Commented Mar 7, 2016 at 3:40
4

@KAndy’s answer put me on the right track, but I am developing locally using vagrant and had to do the following to get this to work1

Configure Xdebug:

zend_extension=xdebug.so
xdebug.remote_enable = 1
;remote_connect_back will fail because REMOTE_ADDR header won’t be set
xdebug.remote_connect_back = 1
xdebug.remote_autostart = 1
xdebug.idekey = "PHPSTORM"
;remote_host is ignored when remote_connect_back is enabled & successful; fallback
;Set to your HOST MACHINE IP
xdebug.remote_host=xx.xx.xx.xx 
;provides valuable insight if you can’t connect. Remove when done.
xdebug.remote_log="/tmp/xdebug.log"

Set the remote_host IP to the IP address of the host (for me, using the IP address from ifconfig on the guest machine did not work - used IP address acquired from the network settings on the host machine as the remote_host).

Configure PHP Storm

  1. Set up a server under Settings -> Languages and Frameworks -> PHP -> Servers if you have not done so already. (See screenshot) Example Server Settings on PHP Storm
  2. Run -> Edit Configurations and add a PHP Remote Debug.
  3. (Optional) Settings -> Languages and Frameworks -> PHP -> Debug Check "Break at first line in PHP Scripts" (this can help debug issues with your path mapping.)
  4. Run -> Debug Vagrant (or whatever you named your configuration in Step 2)
  5. Run the script you'd like to debug (magento setup:upgrade in my case)

1I'm using ubuntu/trusty64 for reference

answered Feb 1, 2018 at 3:18
2

after xdebug 3.0 update

Instead of setting the XDEBUG_CONFIG environment variable to idekey=PHPSTORM, you must set XDEBUG_SESSION to PHPSTORM:

export XDEBUG_MODE=debug XDEBUG_SESSION=1

1
  • 1
    This worked for me! Please note that you don't have to run this each time with a Magento command, as it's saved in the terminal session. Therefore once you ran the export command, you can then run whatever Magento command afterwards. Commented Apr 2 at 14:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.