PHPStorm and Xdebug Primer Tutorial

PHPStorm and Xdebug Primer Tutorial

PHPStorm and Xdebug Primer Tutorial

Though with a large variety of scenarios with code, you can debug a piece of code from the command line … and don’t get me wrong because sometimes the command line will be the only way … the experience of debugging is much better if it is combined with work within an IDE.

In this scenario, what about debugging PHP? We’ve been trying out PHPStorm, we talked about at PHPStorm IDE Primer Tutorial, as shown below, overseeing PHP projects and using the Xdebug debugger.

Roughly speaking, what is required here is, via the Xdebug Configuration advice from JetBrains, the inventors of PHPStorm …

  • If Xdebug is not installed, an Xdebug install would be required … and then …
  • PHPStorm Preferences -> Languages and Frameworks -> PHP -> “…” Button gives you both …
    1. Location of relevant php.ini (which you’ll probably change) … and …
    2. Xdebug (or other debugger) existance status (to tell you if you are getting anywhere)
  • Changes to that php.ini (of above) with, in our case, lots of stops and starts of our local MAMP Apache web server (to see those changes right)

Cutting to the chase what we found could work with our php.ini (after dismantling any pre-existing [zend] section blockages (though we didn’t have this)) was …


[xdebug]
zend_extension="/Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
;zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_port=9123
xdebug.remote_host="127.0.0.1"
xdebug.remote_handler="dbgp"
xdebug.remote_mode="req"
xdebug.remote_connect_back=0
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/Library/pgAgent/Downloads/ansible-deployment/tmp"

… and we have to thank this link, in particular, among many from the Open Source community, which helped … thanks. Perhaps the most contentious configuration above is xdebug.remote_autostart=1 which can cause extreme slowness on occasions … if that is the way for you you may want to make it xdebug.remote_autostart=0 to not have the connection between Xdebug and PHP be checked so often. And the paths shown were specifically suited only here, we hasten to add … dough doh!

Other traps for young players could be …

  • Start Listening for PHP Debug Connections (Run option) is useful (rather than “Stop” … doh!)
  • Set some breakpoints
  • Break at the First Line of Code (Run option) quite useful
  • The initial connection between PHPStorm and Xdebug may take quite some time, and remember to accept the connection, should a connection window appear

Today’s slideshow offering is warts and all as life is when you cannot be sure what happens next?!


Previous relevant PHPStorm IDE Primer Tutorial is shown below.

PHPStorm IDE Primer Tutorial

PHPStorm IDE Primer Tutorial

Unlike compiled software code, PHP code is often coded simply with the use of a good text editor. That doesn’t mean programmers are not looking for a good PHP IDE if it comes along. Today we are going to talk, for the first time at this blog, about a great IDE to use with PHP based projects. It is called PHPStorm for good reason, as it is jam packed full of functionality and features, such as …

  1. PHP Code Editor
    • PHP 5.3, 5.4, 5.5, 5.6 & 7 support
    • smart code completion
    • syntax highlighting
    • extended code formatting configuration
    • on-the-fly error checking
    • code folding
    • language mixture support
  2. Debugging, Testing and Profiling
    • context-relevant local variables and user-defined watches
    • edit values on the fly
    • remote debugging for your server
    • debug in multiple sessions simultaneously
    • keep debugging session alive while moving between pages
  3. HTML/CSS/JavaScript Editor
    • DOM-based, browser-specific completion
    • live editing preview
    • utilize all the power of Emmet (formerly Zen Coding)
    • JavaScript refactorings available are Rename, Extract Variable/Function, Inline Variable/Function, Move/Copy, Safe Delete, Extract embedded script into file
    • automatic compilation/transpilation of modern web development languages to JavaScript (from CoffeeScript, TypeScript, Dart, etc) or CSS (from Sass, SCSS, Less, Stylus, Compass, etc.)
    • JavaScript debugger
    • auto-fixes for such problems as: missing required attributes, invalid attributes or illegal values, wrong references to files in links, duplicate attributes, invalid CSS selector format, invalid CSS properties, unused CSS class definitions, invalid local anchors
    • Angular 2, TSLint, JSLint/JSHint, Node.js, Flow support
  4. Development Environment
    • version control for Git, Subversion, Mercurial, Perforce, CVS, TFS supported
    • tools and code assistance features for work with database and SQL in your projects
    • analyze schema with UML diagrams
    • track any changes made to your source files, protecting you from any accidental losses or modifications
    • helps developers to understand and change their code by providing editable UML class diagrams for PHP code
    • plugin repository contains 250+ IDE plugins of all kinds
    • Vagrant is a handy tool, allowing you to share a development virtual machine, is natively integrated
    • REST Client is integrated in the IDE
    • SSH Console let you connect to any remote machine and perform various actions via SSH
    • Google App Engine applications for PHP development along with ability to delegate routine deployment tasks to the IDE
    • Composer (dependency manager for PHP) is supported
    • pre-configured command completion for various external command-line tools, including Composer, Symfony console, Zend Framework 2 tool (ZFTool), Zend Framework 1 tool, Drush for Drupal, Tools based on Symfony console (Laravel, Doctrine)
    • ability to use a remote interpreter instead of a local one with PHP based application on real server or a virtualized one created with Vagrant
    • completes and checks standard tags, properties, target names, path attribute values in build files, via Phing
    • same integrated development environment on Windows, Mac OS X and Linux with your single key
    • Docker plugin allows user to add Docker support to existing projects, view logs, manage Docker containers
    • if ToDo list is in an issue/bug tracking system, you can configure PhpStorm to work with the issues without switching from the IDE

… and more features can be read about from the PHPStorm website, by JetBrains. The information above comes from the website.

With today’s slideshow, we take up our introductory look at PHPStorm after the install (onto a MacBook Pro laptop using a local Apache MAMP web server) and download, opening some existant PHP code, as a PHPStorm project, which we then Run (or Execute).

We hope this is food for thought for you, in months not starting with M (because we want to remind you to “beware the ides of March” … boom, boom), using the great PHP language in a more integrated and dynamic environment, to hand coded, text edited PHP.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Tutorials and tagged , , , , , , , , , , , , , , , , . Bookmark the permalink.

9 Responses to PHPStorm and Xdebug Primer Tutorial

  1. Stas says:

    I like to use Codelobster to debug PHP projects

  2. Nice blog here olpsostty! Also your site loads up very fast! What host are you using? Can I get your affiliate link to your host? I wish my website loaded up as quickly as yours lol

  3. Exceptional entry! I identified it extremely intriguing. I’ll check back later to see if more posts are added.

  4. Awesome material you fellas got these. I truly like the theme for the web site along with how you organized a person who. It is a marvelous job For certain i will come back and take a look at you out sometime.

  5. Evan Powell says:

    Thank you for all of the labor on this blog. My aunt loves setting aside time for investigation and it’s really easy to see why. We notice all of the lively mode you render precious tactics on the web site and in addition recommend participation from the others on this content then our own simple princess is without question studying so much. Have fun with the rest of the year. You are performing a really good job.

  6. I was looking through some of your blog posts on this internet site and I think this internet site is very informative ! Retain putting up.

  7. Dino Stow says:

    Hi there, You’ve done a fantastic job. I’ll definitely digg it and personally recommend to my friends. I am sure they’ll be benefited from this web site.

  8. F*ckin’ awesome things here. I am very happy to peer your article. Thanks a lot and i’m having a look forward to touch you. Will you kindly drop me a e-mail?

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>