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 …
- Location of relevant php.ini (which you’ll probably change) … and …
- 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.
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 …
- 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
- 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
- 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
- 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.
9 Responses to PHPStorm and Xdebug Primer Tutorial