2016年10月9日 星期日

Debugging a Laravel web application with PHPStorm on Homestead

For someone who has almost always used Sublime Text switching to a full blown IDE like PHPStorm and discovering the debugging feature is like Christmas came early. 


In order to enable PHPStorm to debug your Laravel web application using Xdebug and assuming that you are running a Homestead virtual machine for development these are the steps you have to take.

1. Configure Xdebug on Homestead

SSH into you Homestead machine vm or ssh vagrant@127.0.0.1 -p 2222 and type this: sudo nano /etc/php5/fpm/conf.d/20-xdebug.ini into terminal.
Append the following to the file and save it:
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.scream=0 
xdebug.cli_color=1
xdebug.show_local_vars=1
Restart the php5-fpm service: sudo service php5-fpm restart.

2. Configure PHPStorm

You can follow the instructions bellow or you can watch a free lesson on laracasts - Xdebug and Laravel on how to do this part. Also there is a great tutorial on how to do this by Bruno Skvorc - How to Install Xdebug with PHPStorm and Vagrant.
I have summarized the neccessary steps below if you need a quick start.

2.1. Servers

We need to configure PHPStorm to tell him what server we are using. Go to project settings -> PHP -> Servers and add a new server. 
Give it a port 8000 and under host, put the name of your site’s virtual host (default: homestead.app)
Then, use Path Mappings to map paths so that the location of your project root on the host machine corresponds to the location on the VM. Do the same for the public folder. Just copy the folders block from Homestead.yaml to this window.
https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2014/06/140415347801.gif

2.2. Debug

To run the debugger on the app, we need to create a new debug environment. Go into Run -> Edit Configurations and add a new configuration for “PHP Web Application”:
https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2014/06/140415383904.png
Set server to newly created one and leave all the defaults. Apply the new settings and close the configuration.
Now you have to set breakpoints in your code and go to Run -> Debug applicationand see what happens. 
I hope that you have enjoyed this little tutorial and if you like it or have questions leave a comment below.

Sources


from : https://laravelista.com/posts/debugging-a-laravel-web-application-with-phpstorm-on-homestead

沒有留言:

wibiya widget