I would like to debug PHP in Eclipse PDT while it runs under an Apache server with a bit of MySQL thrown in. In order to do the remote debug one needs to configure PHP to use XDebug which is a standard cross-platform debugger that is used by a variety of languages to debug over the wire. It is based on DBGp, a common debugger protocol for languages and debugger UI communication.
I followed the standard instructions to switch on XDebug except that I installed it under
e:\xampp instead of the default
- Launch the XAMPP Control Panel.
- On the Apache row click Config, then PHP (php.ini) to load the PHP configuration file.
- Forward search for [XDebug]
- Make sure the following options are uncommented (i.e. remove the semi-colon at the front of the line) and fill in the entries to match those below.
[XDebug] zend_extension = "E:\xampp\php\ext\php_xdebug.dll" xdebug.remote_enable = 1 xdebug.remote_handler = "dbgp" xdebug.remote_host = "127.0.0.1" xdebug.remote_port = "9000"
- Stop Apache
- Start Apache
On starting Apache the following message pops up:
The procedure entry point zend_unmangled_property_name_ex could not be located in the dynamic link library php5ts.dll
After a lot of really boring reading in the usual forums and help web sites I find out that the
php_xdebug.dll is not compiled correctly for the version of PHP I'm using. This is very strange because it was downloaded as a bundle so everything should be compatible with everything else, but it wasn't.
To confirm this type:
which gives the following output:
cd e:\xampp\php php -m
Failed loading E:\xampp\php\ext\php_xdebug.dll [PHP Modules] bcmath bz2 calendar Core .... zip zlib [Zend Modules]
Microsoft Windows dictates an internal DLL binary format which coincidentally is released with a new version of Microsoft's Visual studio. This makes programs compiled with different versions of compiler incompatible with each other - thanks for that. It causes problems in every computer language that is compiled with a Microsoft compiler. PHP is just one of them. Python is another. If you compile Python under Visual Studio 9 you will have to recompile all the support modules with the same compiler. So not only do you have to care about whether it was compiled into 32 or 64 bit code but you also have to care about which compiler was used too.
The name of the XAMPP binary tells you which version of Visual 'C' was used to create the application suite. In my case I downloaded
xampp-win32-1.8.2-0-VC9-installer.exe paying special note to the win32 and *VC9** in the file name. From the file name we can see that this is a windows 32 bit version compiled using Visual 'C' 9.
This only gives us some of the story. For the rest we need to run XAMPP and get it to tell us how it was compiled. In the document root
E:\xampp\htdocs create a file called
p.php and fill it with:
Next open you browser and go to: http://127.0.0.1/p.php.
<?php phpinfo(); ?>
There are several lines of importance:
PHP Version 5.4.16 Compiler MSVC9 (Visual C++ 2008) Architecture x86 Zend Extension Build API220100525,TS,VC9 PHP Extension Build API20100525,TS,VC9
phpinfo() confirms that Microsoft's Visual 'C' version 9 (MSVC9) was used as the compiler which was built in Visual C++ 2008. The Visual C++ 2008 tells us that the Apache needs the Visual C++ Redistribution libraries to be installed. You wouldn't be able to run Apache with out them. If may explain why XAMPP may work on a newer server but give DLL errors on an older one.
x86 is the hardware architecture and indicates that it is a 32 bit build.
Zend Extension Build and PHP Extension Build have their compiler options although in this case the only important part of this is the TS bit. I think that in some builds of PHP the TS may not exist or it might be NTS instead.
Next we have to download a new version of XDebug that will fit into our environment. So navigate to: http://xdebug.org/download.php
In the Releases section look for the version that has the compiler flags we need. We'll start with the latest version (XDebug 2.2.3 at the time of writing). I'm using PHP version 5.4 compiled using VC9 with TS and for a 32 bit build. So I download PHP 5.4 VC9 TS (32 bit) (php_xdebug-2.2.3-5.4-vc9.dll).
There are 2 ways to install it.
- Stop Apache
- Start Apache
Windows being what it is with locking files means that you have to stop Apache before copying the DLL in to the correct place which will slightly increase the downtime. This might work better as a tested upgrade on a production system where you don't want to touch the configuration files.
Alternatively you can:
- Edit the zend_extension line in the
php.inito point to this version.
[XDebug] zend_extension = "E:\xampp\php\ext\php_xdebug-2.2.3-5.4-vc9.dll" xdebug.remote_enable = 1 ....
- Stop Apache
- Start Apache
Most people choose this option because it gives you a better infrastructure for testing different versions as well as an easy rollback or upgrade path in case anything goes wrong. It also reminds you which version of XDebug you are using. The DLLs stay in place and you are only changing the configuration files. As a result there is no gap between the Apache restart.
Finally navigate to your
phpinfo() page and there should be a section for XDebug.
Comment from: tall dragon [Visitor]
Comment from: adrian m [Visitor]
Comment from: Martin [Visitor]
I was unhappy the whole day, because my XAMPP doesn’t work !
Just now all work, this is famous article, many thanks David !
Have a nice day Martin
Comment from: Kalinga [Visitor]
Form is loading...