How to debug php in Aptana Studio

This basic tuto­r­ial explain about how we can debug php 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 applications.

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 wizard.

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 again 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.

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:

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. It will take us to next line break­point or exe­cute 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 Cntrl + F2).

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

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>