Logo
  • PHP
    • HipHop / HHVM
    • Modern PHP
    • PHPStorm
    • LAMP
    • Laravel
    • Composer
    • PDO
  • JavaScript
    • node.js
    • AngularJS
  • CSS
    • SASS
    • “CSS4” (CSS level 4)
  • HTML
  • Git
  • LAMP
  • Vagrant
  • UI / UX
  • Architecture of …
  • Off-Topic
With ♥ from Berlin
October 14, 2013
Chris
PHP
Comments Off on How to setup and use XDEBUG with PHPStorm 6/7 (locally in Windows 7/8 and Mac OS X)

How to setup and use XDEBUG with PHPStorm 6/7 (locally in Windows 7/8 and Mac OS X)

PreviousNext
phpstorm 7.0 php

Real debugging is probably one of the most coolest things that are possible in software development: Remember the times where you echoed out everything in your app like

echo $my_value;

just to see the content ? Yeah, there are better tools, like

var_dump($my_value);

or even the awesome krumo which shows your variables/objects in an interactive javascript box, but honestly, that’s amateur stuff!

Real debugging is extremely effective, extremely simple (!) and totally unknown to a large amount of PHP developers.

 

What is debugging ?

To say it in one sentence: You mark a (or multiple) line(s) in your code within your IDE, run your script with the browser (or by command line), and PHP/xdebug will pause your script exactly where the marker is, showing you the value of each variable/object/etc. at exactly that point in time. In your daily work you’ll set multiple markers and jump through your application, pausing/resuming with one click (or keyboard shortcut).

How to setup and use XDEBUG with PHPStorm (locally in Windows 7/8 and Mac OS X)
By the way: If you are not using an IDE like PHPStorm, NetBeans, Aptana etc. TRY IT OUT NOW ! Your life will be so much better. Seriously. In this tutorial we will use PHPStorm, which is currently the most advanced, most intuitive and most value-for-the-money IDE for PHP. It is perfect for debugging as PHPStorm needs absolutely NO CONFIGURATION (!). Love it!

 

Requirements

  1. Install your favourite Apache/MySQL/PHP stack (which has xdebug included), in this tutorial we’ll use AMPPS, which is probably the best (L)AMP stack for windows machines. It’s always up to date, has a very good interface, allows changing of PHP versions with one click, is totally config-free and offers one-click installations of popular PHP scripts, frameworks, CMS, blogs etc.! XAMPP, which is often used by beginners, does not have xdebug included. Mac users may use MAMP, which has xdebug included.
  2. Install PHPStorm.

 

Edit the php.ini

In AMPPS you can edit the php.ini (there is one for every version of PHP by the way !) via clicking the taskbar icon with right mouse button -> Configuration -> PHP. Search for the [xdebug] part, usually at the end of the file. It should look similar to this:

;debugging
zend_extension = D:\Entwicklung\Ampps\php\ext\php_xdebug-2.2.3-5.3-vc9.dll

[xdebug]
xdebug.remote_enable = on
xdebug.remote_handler=dbgp
xdebug.remote_host="127.0.0.1"
xdebug.remote_port=9000
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = off
xdebug.profiler_output_name = cachegrind.out.%t.%p

Don’t change anything here, simply add this line

xdebug.remote_autostart = on

and close the file (will be saved automatically). QUIT the entire AMPPS application (right click in taskbar icon) and start it again. This hard restart is necessary to reload the changed php.ini correctly.

 

Debugging !

Open PHPStorm, create a new and empy project locally, create an index.php and put this into the file:

<?php
$a = 1;
$b = 2;
$c = $a + $b;
$c++;
$d = "test";

echo $d;


Click into the empty space left to some code lines (where the red dots in the example picture are).

 

How to setup and use XDEBUG with PHPStorm (locally in Windows 7/8 and Mac OS X)

 

Click on the “telephone icon”, so it will change and show something green. This will make PHPStorm listen for xdebug sessions and make it pause your scripts every time it hits a marked line.

 

How to setup and use XDEBUG with PHPStorm (locally in Windows 7/8 and Mac OS X)

 

Now open your browser and run the index.php! Please note: You need to access the script exactly via the hostname provided in your php.ini, usually “127.0.0.1”. So you’ll start your demo script via 127.0.0.1/your_folder/index.php! Many people try to do that with http://localhost and wonder why nothing happens.

Your script will now “pause” in the browser and a debug window in PHPStorm will pop up, showing you all the variables in your script and their values at exactly that position where the red marker is. The debugging is highly interactive, you can expand the arrays and objects and even manipulate them: Right-click a variable/property to set another value.
To go on with the script press F9 or click on the green “play” button on the left side of the PHPStorm windows. To completely stop the script, click on the red “stop” button or press CTRL+F2.

 

How to setup and use XDEBUG with PHPStorm (locally in Windows 7/8 and Mac OS X)

Manipulating a value in PHPSTORM via XDEBUG

 

Finally a little tip: You need to press that debug “telephone” button again every time when you start PHPStorm or create a new project.

Also useful: How to debug a PHP application on a remote server (with xdebug)

 

Share this
phpstorm 7.0 php

How to install GitHub’s, NetBeans’s and Sublime2’s syntax highlighting code colours theme in PHPStorm 6/7

PHPStorm’s default code colouring might not be what you want, especially when you just switched from NetBeans. But there are

php mvc

Preview-release of (my) “php-mvc” project (a simple php mvc barebone)

Voila! The very first pre-final release of the “php-mvc” repository is online: https://github.com/panique/php-mvc and http://www.php-mvc.net. It’s a very simple but very

the-php-login-project

How to install php-login-one-file on Ubuntu 12.04 LTS

This tutorial will show you how to install the one-file version of php-login.net‘s login script (see the full GitHub repository

The architecture of StackOverflow

One of the most interesting talks these weeks, and a rare insight into one of the most active pages on

css3-chrome-font

[Link] Retinafy your Site / Device by Nijiko Yonskai

A simple one-page Gist with all the information you need to make your sites retina-ready: Nijiko Yonskai – Retinafy your

digitalocean coupon

Free $10 coupon for DigitalOcean SSD cloud VPS hosting

DigitalOcean puts out another coupon, this time for free $10 with the code SSD2014. The company offers small and big

october cms

[Link] How To Install October CMS on a VPS running Ubuntu 14.04

Quick tutorial on how to install October CMS on Ubuntu 14.04 by DigitalOcean. Worth a bookmark, does the job. I

php

Is there a JSFiddle for PHP ? Yes !

It’s awesome how UNknown these little and extremely powerful tools are: There are some online tools that let you paste

How major web companies (and banks) handle passwords quite wrong

There’s a very interesting “movement” in password handling going on for a long time, the basic idea is to encourage

phpstorm 7.0 php

How to setup and use XDEBUG with PHPStorm 6/7 (locally in Windows 7/8 and Mac OS X)

Real debugging is probably one of the most coolest things that are possible in software development: Remember the times where

1/4

Categories

Search

How to show memory usage (Ubuntu)
Frontend Ops Conf 2014 – Paul Irish: Delivering The Goods In Under 1000ms (40min video)
php
How to use the PHP 5.5 password hashing functions
What’s new in PHPStorm 9
set up a local virtual machine for development with vagrant and puphpet / puppet (and ubuntu, linux, php, apache, mysql)
A list of downloadable Vagrant boxes (CentOS 5.9 / 6.4, Ubuntu 12 / 13, Debian 6 / 7 / 7.1 / 7.2)
This is an experimental advertisement
symfony-framework-logo
SensioLabs, creator of Symfony and Silex PHP frameworks, gets $7 million capital
html6
Is this the first HTML6 specification?
java
Interesting: code of the same application in PHP, Python, Ruby, Closure, node.js, Java and Go
(Links) How to fix an extremely slow Symfony inside a Vagrant box
php ide
Sitepoint asks for your favourite PHP IDE – take part!
How to setup a config-free WordPress, PHP and MySQL (for local development) in Windows 7 / 8 in under 3 minutes
october cms
October CMS, built on top of Laravel, is beautiful, clever and on the way to be the new #1 CMS
php uk conference
PHP Caching Best Practices by Eli White (video from PHP UK Conference 2014)
digitalocean coupon
DigitalOcean VPS coupon codes for december 2013 and early 2014

Tags

apache bash centos composer conference coupon CSS debian fonts framework git GitHub hack HHVM HipHop HTML HTML5 IDE JavaScript JS LAMP laravel linux mod_rewrite MVC MySQL Nginx optimization PHP PHP 5.5 PHP 5.6 phpmyadmin PHPStorm security server SSD Ubuntu UI UX vagrant video virtual machine voucher VPS wordpress
Side-Project: Wordle-Solver:
www.wordle-helper.info

Pages

  • Privacy Policy