Do you love programming in PHP? If you don’t, could it be your editor/IDE?
As a programmer, the tools you use, and how well you use them, can have a huge impact on your productivity.
How much time have you wasted writing var_dump statements and printing log messages?
What if you could just inspect the contents of a variable whenever you wanted?
That’s what debugging allows you to do, and that’s what I do every day.
Not sure what the array keys are? Inspect the variable. Not sure of the object’s properties? Inspect the variable. Not sure if a function is running? Stick a breakpoint on its first line, and see if your program stops execution at that point.
Debugging saves time… But setting up debugging can also take some time, as it requires the installation of xdebug and the correct configuration set-up. Plus, if you’re using a virtual machine like a vagrant box, you’ll need to set up path mappings.
PhpStorm Has Built-in Debugging for xdebug
See that screenshot? If you’re trying to get xdebug to work with phpstorm, and you’ve already installed xdebug, then you should go to: Run –> Web Server Debug Validation (For PhpStorm version 2016.3.2, it’s the last option in that Run dropdown menu.)
When that validation box first opens, you’ll probably see an error message. Click on “validate” and it might work right out of the box. If not, check that the path is set to a location that the web server can serve up. If you already have a project, this can just be the directory to the project. (By default, Apache only serves up files from within a specific directory, and as programmers we usually put our web apps inside that directory, because then we can view them with a web browser.)
Settings for Ubuntu 16.04 with Apache and PHP 7
If you’re running Ubuntu with Apache and PHP locally, make sure that “Local Web Server or Shared Folder” is selected, and enter the following:
Path to create validation script: /var/www/html/
URL to validation script: http://127.0.0.1/
Click Validate….. and PhpStorm will tell you what’s wrong!!
In this case, it was easy. I just had to add xdebug.remote_enable=1 to my php.ini file
And then I just had to restart Apache:
Hope that was helpful!