Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Hide Buttons

How to debug php in Aptana Studio – Part 1

This basic tutorial explain about how we can debug php scripts using the Aptana Studio IDE. The Aptana Studio IDE is distributed by Aptana. It can be downloaded from Aptana Download Page. The IDE is open source and very much helpful in developing and debugging php applications. It assumes that php is already installed. In the next tutorial we will discuss how we can use Aptana to do remote debugging for an web app installed on apache.

Once we download and install Aptana, we can follow the below mentioned steps to create a php project and debug it using XDebug. To start debugging php using Aptana Studio, start the IDE and select a workspace location.

Step 1: To create a project in Aptana, click on File -> New -> PHP Project as shown in below mentioned image.

Create PHP Project using Aptana Studio

 

 

 

 

 

 

 

Step 2: Enter the project name as TestDebugger or any other name of your choice on the project creation wizard and click on Finish to create the Project.

Step 3: Create a new php file for our project TestDebugger. To create a php file, right click on the project explorer area and select New -> New From Template -> PHP -> PHP Template.

Create PHP file Aptana Studio

 

 

 

 

 

 

 

 

 

 

Step 4: It will display the file creation wizard. Enter the filename as hello_aptana.php and make sure that the parent folder is selected as TestDebugger. By default the PHP template file consist of pre-written code within the php code tags as shown below:

 phpinfo();

Step 5: Now let’s remove the default template code and write code to print hello world 5 times on console using for loop. We are going to debug the for loop using XDebug.

    for( $i = 0 ; $i < 5; $i++ ){
    	echo "Hello Aptana Studio";
    }

Step 6: Now add a debug point to stop the debugger. To add a debug point, we can double click on the space before the line number where we want to add our debug point. It’s also called as adding line breakpoint. It’s shown in below mentioned image:

Aptana Studio - Add line breakpoint

 

Step 7: Now we will configure Aptana Studio for PHP executable and XDebug. Go to Windows -> Preferences -> Aptana Studio -> Editors -> PHP -> PHP Interpreters and click on Add Button and fill the form for PHP Interpreter as shown below.The wizard for PHP interpreter ask the location where we have installed PHP for php.exe and php.ini files.  Make sure that you have selected XDebug as your default debugger.

Aptana Studio configure php interpreter

 

Step 8: Click on Finish and than click on ok button.

Step 9: To execute the php file, right click on the hello_aptana.php file and select Run As -> PHP Script. This step will simply execute the php file without stopping at our line break we have inserted in previous steps. It will print “Hello Aptana Studio” 5 times on console.

Step 10: To debug the php file, right click on the hello_aptana.php file and select Debug As -> PHP Script. If the debug perspective is not enabled, the Aptana Studio will ask to switch the current web perspective to debug perspective as shown below:

Aptana Studio debug perspective

 

 

 

 

 

 

Now click on yes button. You can see that your debugger is stopped at the beginning of for loop as shown below:

aptana studio - line breakpoint 2

 

 

 

 

 

 

 

 

 

 

Step 11: To execute the code line by line, we can press F5 or Step Into. The same is available at the top bar of debug perspective as shown below. If we keep pressing F5 it will execute the for loop for each iteration and print the echo message one by one on the Console View. This is how we can debug line by line in Aptana Studio.

aptana studio debug step into

 

aptana studio debug console

 

 

 

 

Step 12: To view all the variables initialized and their value, we can check the Variables view as shown below. If we scroll down, we can see the current value of $i variable of for loop. It will increment for each iteration of for loop.

aptana studio debug variables

 

 

 

 

 

Similar to Step Into, we can perform various debugging actions. We can press F8 or Resume to skip a particular line breakpoint. In this example, if we press Resume(F8) the next line break is same till for loop gets over and it will pause the execution at same breakpoint. It will take us to next line breakpoint or execute and finish our program if there is no further breakpoint.

To remove line breakpoint, we can again double click on the breakpoint.

To stop the debugger, we can press the red button ( Terminate or Ctrl + F2).

This is how we can debug a php program using Aptana Studio and XDebug debugger.

Notes: As thelateniteowl pointed out, our php ini file should enable XDEBUG Extension else the debugger won’t work.

The next part remote debug php explains how we can remote debug php scripts installed on Apache Web Server.

You may also like...

25 Responses

  1. Colin Goldberg says:

    Is there any way to activate/display the “Debug Output” tab/view – next to Console, Tasks, and “Browser Output”? I used to have this available in Eclipse PDT before I moved over to Aptana. I does not seem to be available, but it is, in my opinion, essential to the debugging process (for php at least). Browser Output does not satisfy this need, as it processes any output as html and loses valuable information. Console has a different purpose – it does not satisfy this need either.

    Any suggestions?

    • Bhagwat Chouhan says:

      In eclipse we have this option for PDT : Window -> Show View -> Other -> PHP Tools -> Debug Output.

      The Aptana Studio 3 do not have this option with the default install.

  2. ben says:

    Hi;

    Does anyone know why step over, step into and step return are disabled?

    Thanks

  3. Sarah says:

    Thanks a lot!! For months I was trying to do this.

  4. What about debugging PHP web page? says:

    Thanks, this is a good start. Do you have any guides on how to debug a web application? Specifically, PHP 5.x running a codeIgniter framework with mySQL, etc.

  5. Michael says:

    Can you elaborate a little bit further, on how one goes about debugging a PHP Web application?

  6. David Griffiths says:

    Just what I needed. Just the right level of detail. Many thanks.

    Part two on debugging a script that is being accessed by a web browser would be useful. 🙂

  7. Thiyagesh says:

    Thankyou. This article is great and simple to understand!!!!!

  8. Bhagwat Chouhan says:

    Thanks to all for your valuable feedback. I will resume writing on tutorial horizon as soon as possible.

  9. Carlos says:

    Hello,

    thanks for tutorial. Do you know how to completly stop debug process? CTRL F2 is not working for me.
    If I added some breakpoints on my file, every time I acces that page, the code will stop at breakpoints. I want to do this only when debug process was start or enabled.

    At this time, I use Skip all breakpoints / remove all breakpoints function. There is a way to keep breakpoints on file?

    • Bhagwat Chouhan says:

      Hi Carlos,

      Instead of stopping the debug process, we can run our script without debug. This will help us in keeping our breakpoints safe. When we run in normal mode, the script won’t stop and run as usual.

      Though there is no way I found to stop debug in between and pass all the breakpoints without stopping.

  10. caianhua says:

    Thanks very much! I’m look for this two days, this is very helpful for me.

  11. thelateniteowl says:

    I follow all the instructions here, but when I run debugger it blows right past the breakpoints as if I clicked RUN instead. [F5] doesn’t work either. Any ideas ?

    • thelateniteowl says:

      Did some detective work and found that the [XDebug] section of my php.ini file was completely commented out (which is how it “shipped”, because I never changed it). So I uncommented the entire [XDebug] section (happens to be 10 lines in my installation) and all is now well. FYI: I have XAMPP loaded on a Windows PC so the php.ini file is located in C:\xampp\php. I also discovered the way to get the Debugger view mode in Aptana v3.4.2: Windows -> Open Perspective -> Debug.

  12. Igor says:

    Hii,
    When i try to exe­cute the php file (step 9) I get error:
    “An internal error occurred during: “Launching hello_aptana”.
    Malformed \uxxxx encoding.”
    Somebody can help me?

    • Bhagwat Chouhan says:

      Hi Igor,

      I think it’s just configuration issue. The path for PHP executable and ini file should be correct.

      Executable Path: /usr/bin/php5/php.exe
      PHP ini file: /usr/bin/php5/php.ini

  13. howard says:

    Hi, thank you so much for this excellent step-by-step tutorial. So many, tutorials leave the odd step out and it takes a long time/forever to work out was has been omitted. Brilliant effort

  14. John says:

    when I debug my php file, I get ‘Invalid thread access’ error.
    I use xampp version 1..8.3.3
    how can I fix the problem?
    Thanks in advanced

  1. April 23, 2014

    […] may be my stupid question.I have seen tutorial for configuring debugging on Aptana by this link http://php.tutorialhorizon.com/how-to-debug-php-in-aptana-studio/ , but when I going through that steps I can’t get the php.exe file path for entering […]

  2. August 4, 2014

    […] I am very new in PHP development and I am following this tutorial on PHP debugging using Aptana Studio 2* on Ubuntu: http://php.tutorialhorizon.com/how-to-debug-php-in-aptana-studio/ […]

  3. August 4, 2014

    […] I am using Aptana Studio 3 on a Ubuntu environment and I am following this tutorial: http://php.tutorialhorizon.com/how-to-debug-php-in-aptana-studio/ […]

  4. August 26, 2014

    […] on August 26, 2014 by Bhagwat […]

  5. September 22, 2014

    […] php using Aptana Stu­dio in the pre­vi­ous tuto­ri­als I wrote for win­dows plat­form — Part 1 and Part 2. In this tuto­r­ial we will dis­cuss how we can write a hello world php […]

  6. November 10, 2015

Leave a Reply

Your email address will not be published. Required fields are marked *