Installing Xdebug on xampp for linux
As it’s commonly suggested, tweaking code while it still in development is foolhardy. If your code seems slow while it’s actually doing what it’s suppose to and right , the first is to measure its performance in actual values. It will just be a wasteful action to just try to tweak the code without these types of diagnostics.
A better measure that is accurate, sometimes that actually measure the time taken by a single line of code can be done using a code profiler. A profiler, typically implemented as an extension to the PHP runtime engine, records the delta between the start of a statement and its end, notes the delta between the start and end of a procedure, and captures the total time required to craft a response to an incoming request. With that, you can find the statement, loop, function, class, or library that is slowing down the application. A better profiler could also measure processes memory usage if process time is not the problem.
Xdebug is my preferred profiler for PHP, which also provides stack trace information to debug PHP applications. It generates datafile that can be viewed using KcacheGrind.
Building and installing Xdebug
I will be using a lamp stack based on xampp for linux installed on ubuntu hardy. I here assume you have already installed xampp for linux and put the bin folder in your environment path.
If you have not yet put the bin folder “/opt/lammp/bin” in your path, run at the command prompt
$ export PATH=/opt/lampp/bin:$PATH
if you would like to have that bin folder inserted in your path every time you login
edit the file .bashrc located in your home folder (ubuntu) for other distro it is .bashprofile
$ sudo gedit /hone/salimane/.bashrc
and add at the end of the file
and save it
Download and unpack the tarball, and change to the subdirectory of the source code. Ensure that phpize and php-config are in your shell’s PATH, and prepare to build with phpize.
$ wget http://www.xdebug.org/files/xdebug-2.0.3.tgz $ tar xzf xdebug-2.0.3.tgz $ cd xdebug-2.0.3/ $ phpize Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519 $ ./configure $ make $ sudo make install Installing shared extensions: /opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/
Notice the directory emitted in the last step. You’ll need it in the next step.
After the Xdebug extension is installed, you’re ready to enable and configure the extension.
First create a folder in your temp folder that will holds the data file generated by Xdebug
$sudo mkdir /opt/lampp/tmp/xdebug $sudo chmod a+rwx -R /opt/lampp/tmp/xdebug
Open php.ini in a text editor, and add the following lines.
zend_extension = /opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so xdebug.profiler_output_dir = "/tmp/xdebug/" xdebug.profiler_enable = On
The first line, zend_extension, loads the Xdebug extension. Notice the same directory as the one you noted before. The second line names the directory to place the profiler output. (the one you just created). The third line enables the profiler.
After adding the lines and verifying that your output directory is writable, restart your Web server.
click on phpinfo()
Scroll down to the Zend logo, Xdebug should appear next to the logo if Xdebug has been properly loaded and configured.