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
8

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)

 

This article was written quite a while ago (9 years), please keep this in mind when using the information written here. Links, code and commands might be outdated or broken.

Random articles

  • Stressed and unrelaxed while coding ? Try some ultra-deeply-relaxing ASMR audio clips. It will change your life. Seriously.Stressed and unrelaxed while coding ? Try some ultra-deeply-relaxing ASMR audio clips. It will change your life. Seriously.
  • [RePost] Goodbye LAMP: Going Nginx, NoSQL, HHVM (41min conference talk with Arne Blankerts)[RePost] Goodbye LAMP: Going Nginx, NoSQL, HHVM (41min conference talk with Arne Blankerts)
  • Electronic Arts / Origin offers Battlefield 3 for free (limited promo action) !Electronic Arts / Origin offers Battlefield 3 for free (limited promo action) !
  • GAMESCOM 2014: Awesome Next-Gen ingame graphicsGAMESCOM 2014: Awesome Next-Gen ingame graphics
  • How the PHP session garbage collector really worksHow the PHP session garbage collector really works
  • DEF CON 18 – When your computer got stolen and you can still SSH into it: “Pwned by the 0wner” (22min conference talk)DEF CON 18 – When your computer got stolen and you can still SSH into it: “Pwned by the 0wner” (22min conference talk)
  • [FREE SERVER PROMO] Install GHOST for free on a free SSD server with this coupon[FREE SERVER PROMO] Install GHOST for free on a free SSD server with this coupon
  • Google rolls out Chrome 37, finally fixes horrible font-renderingGoogle rolls out Chrome 37, finally fixes horrible font-rendering
  • How to get a single table out of a massive MySQL .sql database backup file (mysql dump splitter)How to get a single table out of a massive MySQL .sql database backup file (mysql dump splitter)
Share this

8 Comments

  • KhornePony
    May 25, 2015 4:19 pm

    I am worked with PHPStorm for a long while and i never was able to debug PHP properly. The trick was the “icon like a phone”. Thanks!.

    Reply
  • Swathi
    February 10, 2015 6:48 pm

    How do you debug application in phpstorm with the user input values.

    Reply
  • Martin Legris
    September 22, 2014 10:51 pm

    thanks.. AMPPS doesn’t come with xdebug installed anymore :(. Took about an hour to figure that out properly. But worked out in the end.

    Reply
  • Diego
    January 26, 2014 2:03 pm

    tried on IIS with php manager and recommended configuration and it didn’t work. Tried different versions of php 5.3, 5.4.24 and 5.5.3 and no go. No errors, just nothing happens.

    Works fine on my MBP.

    Using Windows 8.1 Pro, IIS 8.5 PHP 5.4.24 and xDebug 2.2.3.

    Reply
  • Jonny
    November 28, 2013 8:07 pm

    Thanks for the tutorial but it isn’t really helpful for those whose xdebug doesn’t work from just uncommenting the xdebug lines in php.ini

    Reply
    • Chris
      November 28, 2013 8:16 pm

      Thanks, but what exactly do you mean ? If you fit the requirements (as noted in the article) it will work perfectly. Some LAMP-stacks don’t come with xdebug, but in this case you have to use another LAMP. This is totally out of the scope of this article.

      Reply
  • craig
    November 9, 2013 12:34 pm

    Thank you for this post. I’ve tried several other tutorials to get PHPStorm, XDebug and MAMP to work on my machine, but yours was the only one that worked. The key was using “127.0.0.1” as the hostname – even if I had put “localhost” in the debug settings it didn’t work, changing both to the IP worked. Thanks again!

    Reply

Leave A Comment Cancel reply

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

php

PHP.net hacked, but most things are fine again

Between 22nd and 24th October 2013 php.net served JavaScript malware (that was built to use security holes in the usually

How to show the available version of a package (before doing apt-get install)

To show the version of the package that will be installed with apt-get install, do apt-cache policy packagename. To show

bitdeli git github stats

php-login goes #2 PHP script worldwide in BitDeli stats

Holy! I just checked the stats of my little php-login hobby project on BitDeli (the tracking service for GitHub) and

organizing css

Jonathan Snook – CSS is a Mess – How to organize CSS in big projects (54min video talk)

This article was written quite a while ago (9 years), please keep this in mind when using the information written

Berlin, prepare for TOA conference (15th – 17th of July)

If you are in Berlin right now (and have 80-300 € to spend and 2-3 days of holidays (or “spontanious

the-php-login-project

How to install php-login-minimal on Ubuntu 12.04 LTS

In this article I’ll show you how to install the minimal version of the php-login.net‘s login script (see the GitHub

Beautiful, minimal WordPress theme ZUKI by Elmastudio (with 30% discount)

First a little disclaimer: I’m not affiliated with the company, don’t get money (or anything else) for saying this and

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

dev coding cards deck

Nice gifts for devs: Nerdy playing-cards decks

Wonderful idea: Playing cards decks for developers. No, not scrum-cards, more the classic stuff. Code:deck $10 plus $5 for shipping

1/4

Categories

Search

pdo-debug
Debug PDO with this one-line function. Yeah!
vagrant
How to setup a (or multiple) server/LAMP-stack inside a virtual machine for local development with Vagrant and PuPHPet
php
New GitHub repo: simple php-long-polling for creating real-time apps
Install MINI in 30 seconds inside Ubuntu 14.04 LTS
vagrant
A super-simple Vagrant LAMP stack bootstrap (installable with one command)
node.js
PayPal drops Java, goes node.js / JavaScript
php
How the PHP session garbage collector really works
frontend-workflow
[german] Modernes Frontend-Development mit Bower, Grunt, Yeoman (45min Video, Thorsten Rinne auf der IPC2013)
php
[Link] Excellent PHP best practices, 2014 style
ubuntu-14-04-lts lamp
How to install/setup a basic LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu 14.04 LTS
laracon-2014-eu-amsterdam
Laracon 2013 – Kapil Verma: Engineering Complex Applications with Laravel 4 (40min video)
The New Era of JavaScript (28min conference talk, Jack Franklin, 2013)
shadow dom
A quick video introduction into Shadow-DOM, the game-changing DOM-subtree-technology
harper reed about big data
Harper Reed – The magic and mystery of Big Data (30min video from Webstock’15)
A collection of beautiful ajax loaders / spinners in pure .svg / CSS

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
 
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT