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
compress-png

Compress png, jpeg, gif and svg up to 90% with Compressor.io

What a fantastic tool: Compressor.io is a totally free service that let you compress png, jpeg, gif or svg files

sass laravel

SASSmeister is a real-time JSfiddle for SASS / CSS. Awesome!

Excellent tool for testing out SASS in real-time! SASSmeister.com offers a responsive (!) interface for quick SASS-to-CSS development with some

JavaScript ECMAScript6 – A short video introduction (5min)

Excellent introduction into the new ECMAScript6, the spec behind JavaScript.

mod-rewrite-ubuntu-14-04-lts

How to enable mod_rewrite in Ubuntu 12.04 LTS

A little note first: This is the most seen way to enable mod_rewrite in tutorials. However, it’s not the best

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

phpstorm-github-code-color-syntax-theme

Get Github’s code colors in PHPStorm (2014 style)

I really love the colors on GitHub’s code previews but couldn’t find any themes that copy that in a beautiful

Meet the developers behind Ableton (14min video)

An excellent short documentation about the developers behind Ableton, the legendary creators of Ableton Live and Push. Without doubt, Live

css

How to center a div vertically and horizontally (modern methods, without fixed size!)

“How to center a div” (inside another div or inside the body itself) is one of the most discussed questions

atomic-design

An introduction into Atomic Design, a super-clean way to style web applications

A super-interesting talk of Brad Frost at beyond tellerrand 2013, explaining the basics of Atomic Design: What is Atomic Design

Ghost

[FREE SERVER PROMO] Install GHOST for free on a free SSD server with this coupon

A little off-topic, but highly interesting: In April 2013 the former User Interface Head of WordPress (and WordPress expert) John

1/4

Categories

Search

angularjs
Two excellent introductions into AngularJS by Todd Motto
Material Design – How Google designed Android L (7min video)
bitdeli git github stats
Get visitor stats for your GitHub repo with BitDeli
php uk conference
PHP Opcache Explained by Julien Pauli (video from PHP UK Conference 2014)
php-phalcon-logo
Which PHP-framework to learn in 2014 ? PHALCON, by far the fastest ever!
ubuntu-14.04-lts
First view: Ubuntu 14.04 LTS brings PHP 5.5 and Apache 2.4
anti block adblock
Show ads to ad-blockering visitors – with PageFair.com
mod-rewrite-ubuntu-14-04-lts
EOL lists of Ubuntu, Debian and CentOS for your server plannings
How to hack time (KUNG FURY promo campaign)
vagrant
How to setup a local server (in a virtual machine) with Vagrant in PHPStorm
hack-php
Facebook releases HipHop (HHVM) 3.0, adds mysqli and support for Hack language
Migrating Wikipedia to HHVM (@Scale Conference 2014)
phpstorm 7.0 php
How to debug code on a remote server (or in vagrant box) with PHPStorm
modern-php
Creator of Slim framework and “PHP – The right way” writes book: “Modern PHP”, available 2015
harper reed about big data
Harper Reed – The magic and mystery of Big Data (30min video from Webstock’15)

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