Eclipse, PDT and XDebug environment for Drupal Development.
In this tutorial I will try to demonstrate how to make my MacBook Air ready for Drupal Development using the following technologies — which is what I use when developing for More than Themes as well.
- Eclipse PDT
- Drupal 7
For the purpose of this demonstration I will also demonstrate how to set a breakpoint in the page.tpl.php file of the Corporate Clean theme and inspect the available variables.
In the second part of this article, which will follow in a few weeks I will also demonstrate the creation of a simple “Hello World” Drupal module using breakpoints and inspecting the available variables there.
According to the default MAMP installation, Apache is running on port 8888 and MySQL accepts connections in the port 8889. The default password for the MySQL root user is also “root”
Eclipse and PDT
PDT 3.0 can be added to an Eclipse installation via the Indigo repository. Additionally there are 3rd party Eclipse distributions that come with Eclipse, PDT and XDebug bundled together. For the purposes of this article I will choose to go with the first option.
There is plenty of available packages for the Eclipse Indigo (3.7.2) release. However, the Eclipse Classic 3.7.2 is fine for our basic foundation. The package can be downloaded from the following link: http://www.eclipse.org/downloads/
Since you are a developer I believe that there is no need for a detailed “How to install Eclipse on my Mac” guide. Should you need this though, there are lots of resources on the matter online.
The PDT will be installed using the Indigo “Update Site”.
- Select “Help » Instal new Software” to bring up the corresponding dialog.
- Select to work with the “Indigo” update site
- Expand the list and check the “PHP development Tools” option
- Make sure “Contact all update site …” is checked.
- Follow the installation wizard accepting all the EULA and restart your Eclipse.
There are no binaries available for Mac and Linux platform. For this reason we should download the sources and compile them. However MAMP comes with XDebug already precompiled and built-in. We only need to enable it for the proper PHP version we want the XDebug to work with.
Since MAMP comes with more than one PHP versions available, we should first check which one is selected.
In my case, I need to edit the php.ini located in the path showed in the next image. Following this I am uncommenting the xdebug line located in the [Zend] section. Important: don’t miss to add the two settings that follow:
xdebug.remote_autostart = “On”
xdebug.remote_enable = “On”
To verify that XDebug is correctly installed, we can create the following phpinfo.php file and point there our browser.
<?php phpinfo() ?>
Eclipse PDT configuration
We now have all the necessary stuff installed in our box. Now it’s time to configure them to work together. To do so, we need to open the Eclipse Preferences dialog following the menu options “Eclipse » Preferences …”, and locate the PHP node from the tree to the left.
As a first step we need to configure the Eclipse PDT to work with the MAMP Apache server. Mind that our server’s port is the 8888 and the document’s root is located in “/Application/MAMP/htdocs”
The “Path Mapping” must also be configured but we will return here later.
Before using the debugger, we must configure the PHP executables properly. Due to the MAMP installation the PHP’s binary files are located in the following path:
We need to open again the Eclipse preferences dialog and locate the “PHP Executables” node. Then we should add a new entry according to the following image:
The final step is the configuration of the “PHP > Debug” according to the following image:
To test our configuration we will create a very simple PHP Project. Remember to ask from the wizard to create this project in your Apache documents folder. We will name our project “xdebug-test”, so this will end up with the creation of the [httdocs/xdebug-test] folder.
Right after, we will create our first php file named hello.php with the following content:
$name = “Smith”;
echo “Hello ” . name;
In this point we need to go back to the PHP Server configuration and add the proper mapping for our project.
Starting the debugger
To start the debugging process we simply need to set a breakpoint, right click on the project and select “Debug As > PHP Web Application”
Right after that, we will be asked to select the corresponding php file, hello.php, and the debugger will stop in the first breakpoint.
For this example we will install a fresh Drupal core accompanied by the very popular Corporate Clean theme.
We have chosen to install this fresh drupal instance into the [xdebug-drupal] folder in the Apache documents root.
To create a new Eclipse PHP project for this Drupal installation we need to start the New Project wizard and mind to select the “Create project at existing location (from existing sources)”. A good practise also is to set the project name equal to the folder name.
An important step here, is to go to the PHP Server configuration and add one more server path mapping entry.
Corporate Clean theme debugging
Everything is now ready to start debugging our Corporate Clean theme. We need to open the page.tpl.php file and set our first breakpoint:
Right after we can start the debugger using the project’s context menu and select the index.php file as our entry point.
Voila, the debugger has stopped in our breakpoint into the page.tpl.php file.
- Debugging PHP using Eclipse and PDT
- Remote debuggind won’t stop at breakpoints
Stavros Kounis is a software developer and web enthusiast, with a great passion for Drupal and web technologies.