Setting up Phpstorm v9 / Homestead for debugging

Setting up Phpstorm v9 / Homestead for debugging

Ok so since the documentation is all over the place I have decided just to put some notes on how get debugging working using phpstorm

  1. To setup php xdebugg the following xdebug variable need to be setup
    • logon vagrant box -> vagrant up
    • vagrant ssh
    • php -i | grep xdebug to filter the php information varibles
      xdebug.remote_enable = off
      xdebug.remote_connect_back = off
      xdebug.idekey = ""
    • To edit php xdebug vi /etc/php/7.0/mods-available/xdebug.ini and change the above variable to
    • xdebug.remote_enable = on
      xdebug.remote_connect_back = on
      xdebug.idekey = "vagrant"
    • Restart the service for the configuration to take place.
    • service php7.0-fpm restart
    • cross-check the setting to be as above using —-> php -i | grep xdebug
  2. Setup vagrant ssh key so phpstorm can use php7.0
    • In order to do this logon use generate private key and copy this to home directory, follow previous doc on setting up Homestead
  3. Ok so fireup phpstorm (v9.0) goto File -> Setting -> Language & Framework -> Php -> Server -> to create a new servers Port 8000, with xdebug option.
    • also setup the path mapping to where the actual windows path to ubuntu path
    • Click Project –> this where local machine where php project path would be
    • Alternate path –> this where on your virtual machine where php project path would be
    • phpstorm1
  4. Configure php interpreter on virtual machine to used by phpstorm
    • Got to File -> Setting -> Language & Framework -> Php -> Remote
    • Click the + sign to add ssh credential –> this so phpstorm can use the php config on the virtual machine using ssh credential as in diagram below
    • Private key file –> is the key created in step
    • phpstorm2
    • Php executable should be able to pick up from /usr/bin/php as in diagram above
  5. Configure the php debug goto File -> Setting -> Language -> Php -> Debug as in the diagram
    • phpstorm3
  6. To test phpstorm –> in project goto app/http/routes.php do following
    • Route::get('/', function()
      {
          $a = [1, 2, 3, 4, 5];
          
          array_pop($a);
      
      	return View::make('hello');
      });
    • Place a breakpoint at $a by click the side of $a –> u should see a red horizontal line across $a
  7. To Run debugger click Run –> Debug and see the browser come up as below
    • phpstorm5
  8. Phpstorm will stop at the breakpoint we had earlier set as below, press Function F8 to go step by step. To create a watch, just click on + sign on watches colomn
    • phpstorm4
  9. Ok so this end the phpstorm setup for debug

Leave a Reply

Your email address will not be published. Required fields are marked *