This basic tutorial explain about how we can debug php 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.
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.
Step 2: Enter the project name as TestDebugger or any other name of your choice on the project creation wizard.
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.
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:
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.
Step 8: Click on Finish and than again 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.
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:
Now click on yes button. You can see that your debugger is stopped at the beginning of for loop as shown below:
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.
Step 12: To view all the variables initialized and their value, we can check the Variables view as shown below:
Similar to Step Into, we can perform various debugging actions. We can press F8 or Resume to skip a particular line breakpoint. It will take us to next line breakpoint or execute 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 Cntrl + F2).
This is how we can debug a php program using Aptana Studio and XDebug debugger.










