In the previous tutorial, we have discussed how we can debug php scripts using Aptana Studio. In this tutorial, we will continue part 1 and learn how we can use Aptana Studio to debug a php webapp deployed on a remote server. Debugging an app is very helpful when we are not sure where is the exact issue and using echo to debug our scripts force us to modify our code. To avoid using echo for debugging purpose, we can use Aptana Studio and XDebug Extension. Another advantage of using debugging is to learn the code which we do not know but use in our projects like any Open Source library.
The pre-requisites to follow this tutorial are:
1. We have gone through the previous tutorial.
2. Apache, Aptana Studio and PHP are installed.
3. Debugging is enabled for php.ini file.
4. In the previous tutorial, we have used the ini file located within the php installation directory. To follow this tutorial, we need to include the ini file present within apache directory. On an windows system having wamp installed, The settings could be:
We also need to configure the PHP Debug options for Aptana as shown below:
The below mentioned steps can be followed to debug a remote app:
Step 1: Configure php.ini file located within apache bin directory. It must have the installation directory set for XDebug extension and the debugger 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 making these changes to php.ini file.
Step 2: Create PHP Project — To create a php project using Aptana Studio, click on File -> New -> PHP Project and than enter a project name of our choice. The important thing is to create the project under www directory of Apache. Though we can use symlinks or alias for our project, but to keep it simple, we will use Apache www directory.
Step 3: Create the project layout for a web project as shown below. In this project, we have created two php files. The php file index.php welcome us and have a link to call debug.php file.
Step 4: Add some code for debugging purpose in the php file debug.php. We will use the same for loop we have used in the previous tutorial.
Step 5: Now we need to create a PHP server in Aptana Studio which connects remotely to Apache Server. It can be done by clicking on Debug -> Debug Configurations and click on PHP Web Page.
To create a new configuration, we need to click on New Launch Configuration as shown above. We can give any name to this configuration. 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 location. The same technique can be used to debug a server located on other machine which allows access to the default xdebug port 9000.
After creating the server for debugging, we need to specify the initial script which will be launched when we run the php web app. The final configuration should look like as shown below:
At last we need to click on Apply Button and than Debug Button. It will launch the initial script page i.e. index.php on the browser.
To trigger the breakpoint on debug.php file, we need to access it by clicking on the Click Here Link on browser. It will take some time for the first time to launch the debugger. Once it starts, it will ask to switch to the Debug Perspective on Aptana Studio as shown below:
Now click on Ok Button and it will open the debug perspective.
Rest of the steps are same as we discussed in previous tutorial. Once we are done with debugging, the rest of the script will be executed and the output will be displayed on browser in case it’s a regular GET request.