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 tuto­r­ial explain about how we can debug php scripts using the Aptana Stu­dio IDE. The Aptana Stu­dio IDE is dis­trib­uted by Aptana. It can be down­loaded from Aptana Down­load Page. The IDE is open source and very much help­ful in devel­op­ing and debug­ging php appli­ca­tions. It assumes that php is already installed. In the next tuto­r­ial we will dis­cuss how we can use Aptana to do remote debug­ging for an web app installed on apache.

Once we down­load and install Aptana, we can fol­low the below men­tioned steps to cre­ate a php project and debug it using XDe­bug. To start debug­ging php using Aptana Stu­dio, start the IDE and select a work­space location.

Step 1: To cre­ate a project in Aptana, click on File -> New -> PHP Project as shown in below men­tioned image.

Create PHP Project using Aptana Studio

 

 

 

 

 

 

 

Step 2: Enter the project name as Test­De­bug­ger or any other name of your choice on the project cre­ation wiz­ard and click on Fin­ish to cre­ate the Project.

Step 3: Cre­ate a new php file for our project Test­De­bug­ger. To cre­ate a php file, right click on the project explorer area and select New -> New From Tem­plate -> PHP -> PHP Template.

Create PHP file Aptana Studio

 

 

 

 

 

 

 

 

 

 

Step 4: It will dis­play the file cre­ation wiz­ard. Enter the file­name as hello_aptana.php and make sure that the par­ent folder is selected as Test­De­bug­ger. By default the PHP tem­plate file con­sist of pre-written code within the php code tags as shown below:

 phpinfo();

Step 5: Now let’s remove the default tem­plate code and write code to print hello world 5 times on con­sole 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 debug­ger. To add a debug point, we can dou­ble click on the space before the line num­ber where we want to add our debug point. It’s also called as adding line break­point. It’s shown in below men­tioned image:

Aptana Studio - Add line breakpoint

 

Step 7: Now we will con­fig­ure Aptana Stu­dio for PHP exe­cutable and XDe­bug. Go to Win­dows -> Pref­er­ences -> Aptana Stu­dio -> Edi­tors -> PHP -> PHP Inter­preters and click on Add But­ton and fill the form for PHP Inter­preter as shown below.The wiz­ard for PHP inter­preter ask the loca­tion where we have installed PHP for php.exe and php.ini files.  Make sure that you have selected XDe­bug as your default debugger.

Aptana Studio configure php interpreter

 

Step 8: Click on Fin­ish and than click on ok button.

Step 9: To exe­cute the php file, right click on the hello_aptana.php file and select Run As -> PHP Script. This step will sim­ply exe­cute the php file with­out stop­ping at our line break we have inserted in pre­vi­ous steps. It will print “Hello Aptana Stu­dio” 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 per­spec­tive is not enabled, the Aptana Stu­dio will ask to switch the cur­rent web per­spec­tive to debug per­spec­tive as shown below:

Aptana Studio debug perspective

 

 

 

 

 

 

Now click on yes but­ton. You can see that your debug­ger is stopped at the begin­ning of for loop as shown below:

aptana studio - line breakpoint 2

 

 

 

 

 

 

 

 

 

 

Step 11: To exe­cute the code line by line, we can press F5 or Step Into. The same is avail­able at the top bar of debug per­spec­tive as shown below. If we keep press­ing F5 it will exe­cute the for loop for each iter­a­tion and print the echo mes­sage one by one on the Con­sole 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 vari­ables ini­tial­ized and their value, we can check the Vari­ables view as shown below. If we scroll down, we can see the cur­rent value of $i vari­able of for loop. It will incre­ment for each iter­a­tion of for loop.

aptana studio debug variables

 

 

 

 

 

Sim­i­lar to Step Into, we can per­form var­i­ous debug­ging actions. We can press F8 or Resume to skip a par­tic­u­lar line break­point. In this exam­ple, if we press Resume(F8) the next line break is same till for loop gets over and it will pause the exe­cu­tion at same break­point. It will take us to next line break­point or exe­cute and fin­ish our pro­gram if there is no fur­ther breakpoint.

To remove line break­point, we can again dou­ble click on the breakpoint.

To stop the debug­ger, we can press the red but­ton ( Ter­mi­nate or Ctrl + F2).

This is how we can debug a php pro­gram using Aptana Stu­dio and XDe­bug debugger.

Notes: As the­laten­i­te­owl pointed out, our php ini file should enable XDEBUG Exten­sion else the debug­ger 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 Out­put” tab/view — next to Con­sole, Tasks, and “Browser Out­put”? I used to have this avail­able in Eclipse PDT before I moved over to Aptana. I does not seem to be avail­able, but it is, in my opin­ion, essen­tial to the debug­ging process (for php at least). Browser Out­put does not sat­isfy this need, as it processes any out­put as html and loses valu­able infor­ma­tion. Con­sole has a dif­fer­ent pur­pose — it does not sat­isfy this need either.

    Any sug­ges­tions?

    • Bhagwat Chouhan says:

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

      The Aptana Stu­dio 3 do not have this option with the default install.

  2. ben says:

    Hi;

    Does any­one know why step over, step into and step return are disabled?

    Thanks

  3. Sarah says:

    Thanks a lot!! For months I was try­ing 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 appli­ca­tion? Specif­i­cally, PHP 5.x run­ning a codeIgniter frame­work with mySQL, etc.

  5. Michael says:

    Can you elab­o­rate a lit­tle bit fur­ther, on how one goes about debug­ging a PHP Web application?

  6. David Griffiths says:

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

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

  7. Thiyagesh says:

    Thankyou. This arti­cle is great and sim­ple to understand!!!!!

  8. Bhagwat Chouhan says:

    Thanks to all for your valu­able feed­back. I will resume writ­ing on tuto­r­ial hori­zon as soon as possible.

  9. Carlos says:

    Hello,

    thanks for tuto­r­ial. Do you know how to com­pletly stop debug process? CTRL F2 is not work­ing for me.
    If I added some break­points on my file, every time I acces that page, the code will stop at break­points. I want to do this only when debug process was start or enabled.

    At this time, I use Skip all break­points / remove all break­points func­tion. There is a way to keep break­points on file?

    • Bhagwat Chouhan says:

      Hi Car­los,

      Instead of stop­ping the debug process, we can run our script with­out debug. This will help us in keep­ing our break­points safe. When we run in nor­mal 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 break­points with­out stopping.

  10. caianhua says:

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

  11. thelateniteowl says:

    I fol­low all the instruc­tions here, but when I run debug­ger it blows right past the break­points as if I clicked RUN instead. [F5] doesn’t work either. Any ideas ?

    • thelateniteowl says:

      Did some detec­tive work and found that the [XDe­bug] sec­tion of my php.ini file was com­pletely com­mented out (which is how it “shipped”, because I never changed it). So I uncom­mented the entire [XDe­bug] sec­tion (hap­pens to be 10 lines in my instal­la­tion) and all is now well. FYI: I have XAMPP loaded on a Win­dows PC so the php.ini file is located in C:\xampp\php. I also dis­cov­ered the way to get the Debug­ger view mode in Aptana v3.4.2: Win­dows -> Open Per­spec­tive -> Debug.

  12. Igor says:

    Hii,
    When i try to exe­cute the php file (step 9) I get error:
    “An inter­nal error occurred dur­ing: “Launch­ing hello_aptana”.
    Mal­formed \uxxxx encod­ing.“
    Some­body can help me?

    • Bhagwat Chouhan says:

      Hi Igor,

      I think it’s just con­fig­u­ra­tion issue. The path for PHP exe­cutable and ini file should be correct.

      Exe­cutable Path: /usr/bin/php5/php.exe
      PHP ini file: /usr/bin/php5/php.ini

  13. howard says:

    Hi, thank you so much for this excel­lent step-by-step tuto­r­ial. So many, tuto­ri­als leave the odd step out and it takes a long time/forever to work out was has been omit­ted. Bril­liant effort

  14. John says:

    when I debug my php file, I get ‘Invalid thread access’ error.
    I use xampp ver­sion 1..8.3.3
    how can I fix the prob­lem?
    Thanks in advanced

  1. April 23, 2014

    […] may be my stu­pid question.I have seen tuto­r­ial for con­fig­ur­ing debug­ging 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 devel­op­ment and I am fol­low­ing this tuto­r­ial on PHP debug­ging using Aptana Stu­dio 2* on Ubuntu: http://php.tutorialhorizon.com/how-to-debug-php-in-aptana-studio/ […]

  3. August 4, 2014

    […] I am using Aptana Stu­dio 3 on a Ubuntu envi­ron­ment and I am fol­low­ing this tuto­r­ial: 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 *