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 2

In the pre­vi­ous tuto­r­ial, we have dis­cussed how we can debug php scripts using Aptana Stu­dio. In this tuto­r­ial, we will con­tinue part 1 and learn how we can use Aptana Stu­dio to debug a php webapp deployed on a remote server. Debug­ging an app is very help­ful when we are not sure where is the exact issue and using echo to debug our scripts force us to mod­ify our code. To avoid using echo for debug­ging pur­pose, we can use Aptana Stu­dio and XDe­bug Exten­sion. Another advan­tage of using debug­ging is to learn the code which we do not know but use in our projects like any Open Source library.

The pre-requisites to fol­low this tuto­r­ial are:

1. We have gone through the pre­vi­ous tuto­r­ial.
2. Apache, Aptana Stu­dio and PHP are installed.
3. Debug­ging is enabled for php.ini file.
4. In the pre­vi­ous tuto­r­ial, we have used the ini file located within the php instal­la­tion direc­tory. To fol­low this tuto­r­ial, we need to include the ini file present within apache direc­tory. On an win­dows sys­tem hav­ing wamp installed, The set­tings could be:

PHP Interpreter configuration

 

 

 

 

 

 

 

 

 

 

 

 

 

We also need to con­fig­ure the PHP Debug options for Aptana as shown below:

PHP Debug

PHP Debug

The below men­tioned steps can be fol­lowed to debug a remote app:

Step 1: Con­fig­ure php.ini file located within apache bin direc­tory. It must have the instal­la­tion direc­tory set for XDe­bug exten­sion and the debug­ger is enabled for remote debug.

zend_extension = "F:/wamp/bin/php/php5.4.16/zend_ext/php_xdebug-2.2.3-5.4-vc9.dll"

[xdebug]
xdebug.remote_enable = On
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_autostart=0

Now restart Apache after mak­ing these changes to php.ini file.

Step 2: Cre­ate PHP Project — To cre­ate a php project using Aptana Stu­dio, click on File -> New -> PHP Project and than enter a project name of our choice. The impor­tant thing is to cre­ate the project under www direc­tory of Apache. Though we can use sym­links or alias for our project, but to keep it sim­ple, we will use Apache www directory.

Create PHP Project

 

 

 

 

 

 

 

 

Step 3: Cre­ate the project lay­out for a web project as shown below. In this project, we have cre­ated two php files. The php file index.php wel­come us and have a link to call debug.php file.

debug-aptana-4

Step 4: Add some code for debug­ging pur­pose in the php file debug.php. We will use the same for loop we have used in the pre­vi­ous tuto­r­ial.

debug-aptana-5

Step 5: Now we need to cre­ate a PHP server in Aptana Stu­dio which con­nects remotely to Apache Server. It can be done by click­ing on Debug -> Debug Con­fig­u­ra­tions and click on PHP Web Page.

debug-aptana-6

debug-aptana-7

To cre­ate a new con­fig­u­ra­tion, we need to click on New Launch Con­fig­u­ra­tion as shown above. We can give any name to this con­fig­u­ra­tion. To add a new server, we need to click on the plus icon next to PHP Server select box. We can give any name to this server and the base url based on server loca­tion. The same tech­nique can be used to debug a server located on other machine which allows access to the default xde­bug port 9000.

Add PHP Server

After cre­at­ing the server for debug­ging, we need to spec­ify the ini­tial script which will be launched when we run the php web app. The final con­fig­u­ra­tion should look like as shown below:

debug-aptana-9

At last we need to click on Apply But­ton and than Debug But­ton. It will launch the ini­tial script page i.e. index.php on the browser.

debug-aptana-10

To trig­ger the break­point on debug.php file, we need to access it by click­ing on the Click Here Link on browser. It will take some time for the first time to launch the debug­ger. Once it starts, it will ask to switch to the Debug Per­spec­tive on Aptana Stu­dio as shown below:

Switch Debug Perspective

Now click on Ok But­ton and it will open the debug perspective.

debug-aptana-12

Rest of the steps are same as we dis­cussed in pre­vi­ous tuto­r­ial. Once we are done with debug­ging, the rest of the script will be exe­cuted and the out­put will be dis­played on browser in case it’s a reg­u­lar GET request.

You may also like...

1 Response

  1. August 26, 2014

    […] next part remote debug php explains how we can remote debug php scripts installed on Apache Web […]

Leave a Reply

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