Recently, I have been asked to help install and setup XDebug along with Webgrind in a Mac OS X system using SSH on one of my colleague’s system. All of this setup were done remotely from another system. Here are the steps/commands for achieving the same.
Steps for installing Xdebug:
- Get the information about installed PHP on the system. This is needed to get the custom installation instructions from xdebug website here: http://xdebug.org/wizard.php
1234clearphp -i - Get the url for the latest xdebug script and download it to your mac.
12345sudo cd /tmp/ && curl http://xdebug.org/files/xdebug-2.2.5.tgz > xdebug.tgztar -xvzf xdebug.tgzcd xdebug-2.2.5/ - Compile and build the php extension from the source. Install the same.
123456phpize./configuremakesudo make install - Enable Xdebug in the php.ini file.
- Find the complete path of the xdebug.so file prior to editing the php.ini file. The path looks something like this: /usr/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so Can be located using the command:
123locate xdebug.so - Edit the php.ini file and add the following lines to the extreme end.
1234cd /etc/sudo nano php.ini
1234567[xdebug]zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20100525/xdebug.soxdebug.file_link_format="txmt://open?url=file://%f&line=%1"xdebug.remote_enable = Onxdebug.remote_autostart = 1 - Restart Apache.
123sudo apachectl restart
- Find the complete path of the xdebug.so file prior to editing the php.ini file. The path looks something like this: /usr/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so Can be located using the command:
Setup Webgrind:
- Download and put Webgrind source into a folder in webserver. ( /Users/subharanjanm/Sites/webgrind/ in my case )
12345cd /Users/subharanjanm/Sites/sudo git clone https://github.com/jokkedk/webgrind.gitcd webgrind/ - Create a folder inside /private/var/tmp/ to store and read profiler files by Xdebug and Webgrind. This step can be skipped if you want to use the “tmp” directory directly to write files.
1234sudo mkdir /private/var/tmp/xdebugprofilers/sudo chmod 777 /private/var/tmp/xdebugprofilers/
- Make changes needed in the Webgrind config file.
123sudo nano config.php
1234static $storageDir = '/private/var/tmp/xdebugprofilers/';static $profilerDir = '/tmp/xdebugprofilers/'; - Finally add following lines into php.ini below the xdebug settings to enable profiler and its related paths.
123sudo nano /etc/php.ini123456xdebug.profiler_enable = 0xdebug.profiler_enable_trigger=1xdebug.profiler_output_dir = "/private/var/tmp/xdebugprofilers/"xdebug.profiler_output_name = cachegrind.out.%t.%p -
123sudo apachectl restart
Now you can append ?XDEBUG_PROFILE=1 into the url of your php script to see the profiling data on Webgrind interface.