I like to start my blog with a small tutorial where i do explain, how you can debug remotely in PHPPHP is a general-purpose server-side scripting language originally designed for Web development to produce dynamic Web pages. It is among one of the first developed server-side scripting languages to be embedded into an HTML source document, rather than calling an external file to process data. Ultimately, the code is interpreted by a Web server with a PHP processor module which generates the resulting Web page. It also has evolved to include a command-line interface capability and can be used in standalone graphical applications. PHP can be deployed on most Web servers and also as a standalone shell on almost every operating system and platform free of charge. using XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end..
Motivation
Especially Java and .NET developers are familiar with many good tools to debug their application. When we talk about web development debugging is not as easy as it is i.e. for desktop applications, because we often have server-side code.
Microsoft’s Visual Studio starts a local server and does automatically connect to this process for debugging your code, when you develop a web application. In PHPPHP is a general-purpose server-side scripting language originally designed for Web development to produce dynamic Web pages. It is among one of the first developed server-side scripting languages to be embedded into an HTML source document, rather than calling an external file to process data. Ultimately, the code is interpreted by a Web server with a PHP processor module which generates the resulting Web page. It also has evolved to include a command-line interface capability and can be used in standalone graphical applications. PHP can be deployed on most Web servers and also as a standalone shell on almost every operating system and platform free of charge. you do not have a local server by default. You can install a AMP-stackApache, MySQL, PHP solution stack. This software bundle is used to run dynamic Web sites or servers. LAMP (for Linux); WAMP (for Windows); MAMP (for Macintosh); SAMP (for Solaris); and FAMP (for FreeBSD). on your machine for developing local, but your IDEAn integrated development environment (IDE) (also known as integrated design environment, integrated debugging environment or interactive development environment) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of: a source code editor, a compiler and/or an interpreter, build automation tools, a debugger. does not automatically connect to the webserver and listen to debug events. You have to install additional software to enable debugging on a local machine. There are different options [1]. I personally prefer XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end. [2]. One reason is that you are able to debug remotely with XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end..
Show: The future – a php-build-in-werbserver »
Please note that with PHPPHP is a general-purpose server-side scripting language originally designed for Web development to produce dynamic Web pages. It is among one of the first developed server-side scripting languages to be embedded into an HTML source document, rather than calling an external file to process data. Ultimately, the code is interpreted by a Web server with a PHP processor module which generates the resulting Web page. It also has evolved to include a command-line interface capability and can be used in standalone graphical applications. PHP can be deployed on most Web servers and also as a standalone shell on almost every operating system and platform free of charge. 5.4 a php-build-in webserver will be available. I guess there will be an option to use it for debugging in future!
Debugging locally is a nice improvement to have no debugger at all, but in many situations there is the need to debug on production server, where the application is running on the web. There are different reasons for that, but the most important one for me is, that my local environment / installation is different from the one i have on servers in data center and bugs can be related to the environment.
Installation
Installing XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end. is very easy, because XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end. is a available as PECLPECL is a repository for PHP Extensions, providing a directory of all known extensions and hosting facilities for downloading and development of PHP extensions. extension. (Note that the following commands for debian/ubuntu may be slightly different for other linux distributions):
To install a PECLPECL is a repository for PHP Extensions, providing a directory of all known extensions and hosting facilities for downloading and development of PHP extensions. extension you need to install PEARPEAR is a framework and distribution system for reusable PHP components. first. Be sure that you have installed PEARPEAR is a framework and distribution system for reusable PHP components. and continue then with installing the XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end. PECLPECL is a repository for PHP Extensions, providing a directory of all known extensions and hosting facilities for downloading and development of PHP extensions. extension:
|
|
sudo apt-get install php-pear
sudo apt-get install php5-dev |
Configuration
Server-side
After the installation is finished open your php.ini and add the following line to the extension section:
|
|
zend_extension=/usr/lib/php5/{BUILDDATE}/xdebug.so |
Please do not miss that you have to use ‘zend_extension’ instead of ‘extension’ and that you have to replace {BUILDDATE} with the date you found in your php5 lib folder.
|
|
xdebug.remote_enable=1 # enable remote debugging for all hosts, which use this php.ini
xdebug.remote_handler=dbgp # debugger protocol, you may change this value to 'gdp' if your IDE is supporting only this
xdebug.remote_mode=req # Xdebug tries to connect to your IDE as soon as you start a script, you can choose 'jit' when Xdebug shall connect to our IDE only when an error condition occurs
xdebug.remote_port=9000 # default port for Xdebug
xdebug.remote_host=aaa.bbb.ccc.ddd # the IP of the remote debugger (your local IP)
xdebug.remote_autostart=0 # Xdebug does only start when you set GET/POST/COOKIE variable, if you set it to '1' Xdebug starts a debugging session on every script call |
Congratulation, you have installed and configured XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end. with a basic setup. Before continueing with additional steps and settings, i recommend to read the following advices:
Show: Important notes on remote debugging »
Do not set ‘xdebug.remote_autostart’ to ’1′, because every visitor of your page would start an XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end. session then. This is annoying and can be a serious performance problem. If ‘xdebug.remote_autostart=0′ and ‘xdebug.remote_mode’ set to ‘req’ everybody who set the GET/POST/COOKIE variable can start a debugging session. Obviously normal visitors would not do that, nevertheless i suggest to avoid that by setting-up a second virtual host with a testing system which is a clone of your production system. Both virtual hosts can still share a common php.ini where you set ‘xdebug.remote_enable’ to ’0′. To enable remote debugging for the virtual host of your testing system, set ‘php_flag xdebug.remote_enable on’ in virtual host configuration.
Debugging Proxy
When you are working alone you are now able to use XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end., but when you work in a team where multiple people like to debug parallel or from different machines you have a problem, because you can only enter one IP address in php.ini as xdebug.remote_host. Since changing the IP address in the configuration file or sharing a single machine for debugging is not a nice solution, you should install a proxy for XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end.. With this proxy you are able to connect with multiple machines at the same time to XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end. and open multiple parallel debugging sessions. (Attention: you have to set xdebug.remote_handler to ‘dbgp’ if you like to use the proxy.) Komodo offers such a proxy. Please download the ‘Python Remote Debugging Client’ which does fit to your server sytem [3].
Extract the files and locate the pydbgpproxy file. If necessary apply:
Now, you can start the proxy with the following command:
|
|
./pydbgpproxy -i eee.fff.ggg.hhh:9001 -d 127.0.0.1:9000 |
eee.fff.ggg.hhh is the public IP of the server, 9001 is the port on which the proxy is listening for connections of debugging clients, 127.0.0.1 is your local loopback address and 9000 is the port on which the proxy is listening to debugging sessions from XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end.. Please do not forget to reconfigure your php.ini and to change the ‘xdebug.remote_host’ to the loopback address ’127.0.0.1′, too! If you like to make sure, that the proxy is running after a reboot, do not forget to write a start script for that purpose or to add an entry in your crobtab.
Show: Security Risk Proxy »
If you enable your proxy to listen to the public IP address, foreigners can register with your proxy and attach themselves to debugging sessions. Although the risk, that this happens is not that big, i recommend to create a virtual private network and add all developers and your server to it. Then you can configure the proxy to only listen on connections from machines in your VPN.
Client-side
To debug your application you still have to configure your IDEAn integrated development environment (IDE) (also known as integrated design environment, integrated debugging environment or interactive development environment) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of: a source code editor, a compiler and/or an interpreter, build automation tools, a debugger.. How to configure it in detail depends on your IDEAn integrated development environment (IDE) (also known as integrated design environment, integrated debugging environment or interactive development environment) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of: a source code editor, a compiler and/or an interpreter, build automation tools, a debugger.. In general you have to set the server IP ‘eee.fff.ggg.hhh’ and the port (9001). You should also set an unique ‘ide key’ for each machine to ensure that, when you work in a team, your IDEAn integrated development environment (IDE) (also known as integrated design environment, integrated debugging environment or interactive development environment) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of: a source code editor, a compiler and/or an interpreter, build automation tools, a debugger. gets only attached to debugging sessions started by yourself. In some IDEsAn integrated development environment (IDE) (also known as integrated design environment, integrated debugging environment or interactive development environment) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of: a source code editor, a compiler and/or an interpreter, build automation tools, a debugger. you also have to enable the debugging mode by making the IDEAn integrated development environment (IDE) (also known as integrated design environment, integrated debugging environment or interactive development environment) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of: a source code editor, a compiler and/or an interpreter, build automation tools, a debugger. listening to connections from the debugger and to manually register to the proxy with your IDEAn integrated development environment (IDE) (also known as integrated design environment, integrated debugging environment or interactive development environment) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of: a source code editor, a compiler and/or an interpreter, build automation tools, a debugger. first.
To initiate a debugging session you now have to set a GET/POST/COOKIE variable in your favorite browser. Since GET and POST variables are used to control the flow of your application and get lost with every page change, i recommend to set COOKIE variables. There are useful browser extensions for setting these variables automatically (i.e.: XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end. helper for Chrome [4] or easx XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end. for Firefox [5]). When you configure them do not forget to set the ‘ide key’ to the same value as you set in your IDEAn integrated development environment (IDE) (also known as integrated design environment, integrated debugging environment or interactive development environment) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of: a source code editor, a compiler and/or an interpreter, build automation tools, a debugger.!
To have a good debug experience you should take care, that the code on the developer machine is the same as on the server. If this is not the case debugging will fail.
Now XdebugXdebug is a PHP extension which provides debugging and profiling capabilities.
It uses the DBGp debugging protocol.
The debug information that Xdebug can provide includes the following:
stack and function traces in error messages with: full parameter display for user defined functions with: function name, file name and line indications; support for member functions; memory allocation; protection for infinite recursions.
Xdebug also provides: profiling information for PHP scripts; code coverage analysis; capabilities to debug your scripts interactively with a debugger front-end. including a proxy is installed and configured and you can start your debuggins sessions.
I hope you like this tutorial, and please do not hesitate to ask your questions or to comment this post. Happy debugging!
Useful links