Saturday, September 14, 2013

Setup for Debugging PHP code on Mountain Lion OS X with XAMPP and PhpStorm

I faced hard time configuring system to debug PHP code on localhost. Thought of archiving it before I forget! I started out with this very useful gist: but there were few changes in the context of Mountain lion and XAMPP.

Xdebug is shipped along with Mountain Lion, so the new MacOSX users need not download it. We have to configure the system to use it.

1. Configuring the php.ini file to enable Xdebug: Usually we find the php.ini file in '/etc/php.ini'. But if you are running XAMPP to create a local webserver, make sure that you edit the php.ini file in the location: '/Applications/XAMPP/xamppfiles/etc/php.ini'. Add the following lines at the end of your php.ini file:


Please note the location of file. The Mountain Lion is shipped with Xdebug and it's default location is "/usr/lib/php/extensions/no-debug-non-zts-20090626/" but I suppose when we install XAMPP, it moves a copy over for itself in the location "/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/". This could be confirmed by checking the phpinfo's extension folder location:

All set, now run this php script in your local webserver to confirm that Xdebug is setup:

<?php phpinfo(); ?>

Now to you should have a dedicated Xdebug section in the phpinfo:

 2. Now we need to setup the PhpStorm with the root folder of the PHP scripts which we want to debug. It's easy to create a project with all the files of your root folder containing the PHP code:

Next comes configuring the project for the PHP web application:

Go to Menu Run > Edit Configuration

Next, click the '+' button to add a new PHP web application:

Now configure the root folder for your PHP resources in this newly created Web Application:

Now setup the server for this project:

This is the setup for PHPStorm. Now, if you could open your index.php in the navigator and place a breakpoint you can confirm it. When you click on the 'debug' menu, a URL is triggered in default web browser something like:

PHPStorm supposedly uses this Xdebug session for debugging purpose. If you want to test and debug webservices, that is possible using the same debug session:


All this done saying, now I have to start debugging and resolve my actual problem!

PS: I am a beginner and am eager to learn new things, there maybe some errors in this post and also I may have gone wrong in my understanding. I would welcome people correcting me and giving their views. If you have questions I will try my best to address them.

1 comment:

  1. Sorry this is question is about a post you made some where else. I have tried to find an answer everywhere and failed, so this is a disparate attempt. I have been playing around with a script that allows users to add photos to a Google drive form. I have it working fine but I want to add the script to a form I have already created. I have no clue how to do this, do you know?

    Any help would be awesome