Since writing the post below I have swapped over to NetBeans 7 (PHP version) and XDebug … they are also free, plus it only took me 10 mins to set everything up, so read on :)
I continued to experience issues with the Zend set up – both with IDE features and ZendDebugger; for example, I was not always seeing changes that had been made to my code (as if it a cached version was sometimes being run) and I was not able to set cookies/sessions when running the app via the IDE. I expect these issues could have been resolved, but the setup:coding ratio I was experiencing was unsatisfactory & I found myself screaming “I just want to code!”
Setup of NetBeans & XDebug took less than 10 minutes including finding and installing the install files, and I’ve yet to find any major issues, even though Netbeans 7 is only in beta (on the couple of occassions something minor hasn’t worked as expected, the excellent built in bug-reporting feature has prompted me to add more details & submit the issue - Zend take note).
My current setup is:
- NetBeans 7 PHP version (beta) . That particular url may not be active for long, so also try http://netbeans.org/index.html
- XDebug – This link takes you to an excellent script that will automatically determine the version of the dll that you need to download, taking away all the hassle & headache (Zend take note again!)
- WAMP – I normally use XAMPP but, as the post below describes, I installed WAMP to solve an issue with ZendDebugger & decided to stick with it.
Once NetBeans & XDebug were installed I just needed to amend php.ini and restart the server. Because I’m using WAMP, I used this post & simply copied what had been posted by dcizal (thanks dcizal!) If your setup differs you should easily be able to find what you need on the NetBeans or XDebug forums.
So, it turns out that finding a decent PHP IDE with debugging, and setting it up doesn’t have to reduce you to tears. Who would have thought it?! ;)
… here is the original post:
Basic Debugging Setup
I wanted to write a quick PHP related post to help ease the pain for Flex developers, setting up an IDE which has the ability to do ‘site-wide’ debugging for PHP projects. This isn’t a “from-scratch” type post. I only really want to cover some of the things that may trip you up if you are a front-end developer and this kind of thing isn’t your strong point.
I’ll write it with this great guide in mind (the guide only concerns itself with setting up the ‘site-wide’ debugger part, so I’ll fill in some of the blanks) :)
Okay, I called it ‘site-wide’, what I mean by that is that you can debug your entire PHP website/app as a whole. It’s actually referred to as ‘remote debugging’ (as your site is running on a server, even if it is localhost) but I wanted to make the distinction because for us Flex developers, application-wide debugging is just ‘debugging’ (we also have ‘remote-debugging’). Anyhoo … the PHP debugger we’re going to use lets you debug a single PHP page, or, debug the site/app as a whole … for which you need to implement remote debugging. Got it?
Stuff To Get
A common free setup seems to be Eclipse with the PDT plugin, and Zend Debugger for debugging, so that’s what I’m using.
The company Zend have made a free contribution to the PHP community, which is Eclipse already bundled with PDT and Zend Debugger – useful!
Also, I’m going to use an all-in-one installer for PHP, MySQL and Apache, and once we’ve done all that, all that’s left to do is to download the files required to enable remote debugging! Go get all this stuff:
- PDT (Zend Build) (All in one IDE based on Eclipse – it comes bundles with the client-side Zend debugger – hurrah!)
- Studio Web Debugger (You’ll need this for remote debugging)
- WAMPP (if you already have PHP, MySQL, Apache set up & didn’t use WAMPP, make sure you read the note below)
Important Note For Non-WAMPP Users
In order to get remote debugging working we are going to have to place a .dll file on to our server (i.e. on localhost). The version of this file MUST match the version of PHP we are using. We must also decide whether to use the thread-safe or non-thread-safe (nts) version of the .dll – the guide I linked to above explains how to determine this, but don’t worry about it just yet.
So what does this have to do with WAMPP? Well, at the time of writing, all of the all-in-one PHP/APACHE.MYSQL installers I have found come bundled with PHP version 5.3, yet the debug .dll file version only goes up to 5.2 and I can testify that if you mismatch the versions, things will simply not work and you’ll get no feedback as to why ;)
I chose to use WAMPP as the way to install PHP, Apache & MySQL because it has a cool feature. WAMPP lets you change the version of PHP you’re using very easily via its control panel. This proved invaluable to me as I was able to downgrade to version 5.2 quickly. This feature may be invaluable to you too if there is a version mismatch when you’re trying to get things working. Of course you could manually (re)install PHP and do all the setup yourself but do you want to go through all that for a simple dev environment? ;)
Installing The Stuff You Got
Install WAMPP and check apache is running by accessing localhost. I won’t go through that in detail, as you can find explanations all over the web, and it’s very straight forward.
Now unpack PDT. Anyone familiar with Eclipse will probably already know that you don’t need to install anything, you can just find and run the eclipse.exe and you’re away! I set my Eclipse workspace to be the document root folder of WAMPP (in my case C:\wamp\www ) so that all my projects are instantly runnable on the local server – I’m sure there is a better way (let me know!). I then set up a new project, created a PHP file for it and added some breakpoints to the file. It was all very straightforward after coming from a Flex environment.
You can debug a simple PHP file straight away as long as you only want to debug it as a single file. Just debug it as you would in Flex – be sure to choose “Debug as PHP Script” from the debug menu (the little bug icon).
Finally we need to get the remote debugging working. For this, see the guide. The guide is in-depth. Follow it closely. Some of the boxes in the guide are scrollable, so make sure you scroll down to see all the code you should be adding in to your php.ini file, and make sure you do things like restart apache after you’ve made the changes.
I’ve covered most of the potential error points in this post already, but I’ll recap – these will make more sense once you’ve read the guide:
- Make sure that your version of PHP matches the version of the ZendDebugger.dll that you place on the server (ie. if you are using PHP: 5.2.4 then use the debugger .dll from the 5.2.x folder). If there is a version mismatch then use the WAMPP control panel … or whatever other means available … to downgrade the version of PHP you are using.
- Do NOT use the ZendDebugger.dll from a folder containing the letters nts (i.e. 5_2_x_nts_comp) unless your PHP installation is non-thread-safe (see guide)
- Re-read each step carefully – for example, don’t go adding
zend_extensionto your php.ini file when you meant to add
- Check your phpinfo() page when you think you’ve got the dll sorted – it should be showing that debugging is enabled . Get this part working before you start worrying that any problem you have may lie with the IDE (see guide for instructions on the message that should be showing).
- If you do run in to problems: check that you can access localhost (127.0.0.1) from your browser , make sure you can ping 127.0.0.1 , make sure you have restarted Apache after making changes to the php.ini file, make sure you have changed the **correct** ini file and look on the web as there is a lot of help out there :)
Okay, so if everything is working properly, you should now be able to choose ‘Debug As PHP Web Page’ from the debug menu and your breakpoints should get hit, rather than being ignored.
The post is a bit rushed I know, but I wanted to get down the salient points for those of you that may be stuck. I hope it helps :)