5 steps to install XHProf + XHGui on MacOS El Captain
Posted: November 10th, 2016 | Author: Alex Iordache | Filed under: General | No Comments »PHP (Symfony) Profiling with XHProf and XHGui
- Verify if PECL is installed. If it is not installed, install PEAR then PECL:
#which pecl
#which pear
#port search –name –line –glob 'php*' |grep -i pear
php5-pear 20161027 php www Obsolete port, replaced by php55-pear
php53-pear 20161027 php www Optional port adds the PEAR repository to the include path for php53.
php54-pear 20161027 php www Optional port adds the PEAR repository to the include path for php54.
php55-pear 20161027 php www Optional port adds the PEAR repository to the include path for php55.
php56-pear 20161027 php www Optional port adds the PEAR repository to the include path for php56.
php70-pear 20161027 php www Optional port adds the PEAR repository to the include path for php70.#sudo port install php55-pear
No trace of PECL on the system yet so try another PEAR installation:
#sudo curl -o /usr/local/bin/pear http://pear.php.net/go-pear.phar
#sudo chmod +x /usr/local/bin/pear
#which pecl
It seems that PECL did not install with the methods above so take the third approach:
#sudo php /usr/lib/php/install-pear-nozlib.phar -d /usr/local/lib/php -b /usr/local/bin
#which pecl
/usr/local/bin/pecl
2. Install the modules for PHP starting with XHProf:
#php -v
PHP 5.5.38 (cli)
#port search –name –line –glob 'php*' |grep -i xh
php-xhprof 0.9.4 php devel A Hierarchical Profiler for PHP
php53-xhprof 0.9.4 php devel A Hierarchical Profiler for PHP
php54-xhprof 0.9.4 php devel A Hierarchical Profiler for PHP
php55-xhprof 0.9.4 php devel A Hierarchical Profiler for PHP
php56-xhprof 0.9.4 php devel A Hierarchical Profiler for PHP
#sudo port install php55-xhprof
3. Before installing the XHGui module for php, install its requirements: MongoDB and its PHP modules:
#port search –name –line –glob 'php*' |grep -i mongo
php-mongo 1.6.14 php databases devel Mongo Database Driver
php-mongodb 1.1.9 php databases devel MongoDB Database Driver
php53-mongo 1.6.14 php databases devel Mongo Database Driver
php53-mongodb 1.0.1 php databases devel MongoDB Database Driver
php54-mongo 1.6.14 php databases devel Mongo Database Driver
php54-mongodb 1.1.9 php databases devel MongoDB Database Driver
php55-mongo 1.6.14 php databases devel Mongo Database Driver
php55-mongodb 1.1.9 php databases devel MongoDB Database Driver
php56-mongo 1.6.14 php databases devel Mongo Database Driver
php56-mongodb 1.1.9 php databases devel MongoDB Database Driver
php70-mongodb 1.1.9 php databases devel MongoDB Database Driver#sudo port install php55-mongodb
#sudo port install php55-mongo
#ls /opt/local/lib/php55/extensions/no-debug-non-zts-20121212/
mongo.so mongodb.soOn my system the modules were placed in another folder than the one where PHP is configured so a copy is needed:
#sudo cp /opt/local/lib/php55/extensions/no-debug-non-zts-20121212/mongo* /usr/lib/php/extensions/no-debug-non-zts-20121212/
#sudo cp /opt/local/lib/php55/extensions/no-debug-non-zts-20121212/xhprof.so /usr/lib/php/extensions/no-debug-non-zts-20121212/
Continue by enabling the extensions:
#sudo vi /etc/php.ini
extension=mongo.so
extension=mongodb.so
extension=xhprof.so
This command actually installs the MongoDB database. The ones above installed the php driver only :
#brew install mongodb
#sudo chgrp staff /usr/local/var/log/mongodb /usr/local/var/mongodb
#sudo chmod 0775 /usr/local/var/log/mongodb /usr/local/var/mongodb
Add this to /usr/local/etc/mongod.conf:
processManagement:
fork: true#mongod –config /usr/local/etc/mongod.conf
Optional, use a tool to install Pref into System Preferences in order to start mongodb
#cd <downloads>
#wget https://github.com/remysaissy/mongodb-macosx-prefspane/raw/master/download/MongoDB.prefPane.zip
#unzip MongoDB.prefPane.zip
double-click on MongoDB.prefPane to install it and launch it
4. Install XHGui and configure it as a Virtual Server:
#cd <some directory for xhgui>
#git clone https://github.com/perftools/xhgui.git
#cd xhgui/
#chmod 0777 cache/
#php install.php#sudo vi /etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/Sites/xhgui/webroot"
ServerName xhgui.lh
ServerAlias www.xhgui.lh
ErrorLog "/private/var/log/apache2/xhgui.lh-error_log"
CustomLog "/private/var/log/apache2/xhgui.lh-access_log" common
</VirtualHost>#sudo vi /etc/hosts
127.0.0.1 xhgui.lh www.xhgui.lh#sudo apachectl restart
Optional, but recommended: Add indexes to MongoDB to improve performance. (https://github.com/perftools/xhgui)
# mongo
use xhprof
db.results.ensureIndex( { 'meta.SERVER.REQUEST_TIME' : -1 } )
db.results.ensureIndex( { 'profile.main().wt' : -1 } )
db.results.ensureIndex( { 'profile.main().mu' : -1 } )
db.results.ensureIndex( { 'profile.main().cpu' : -1 } )
db.results.ensureIndex( { 'meta.url' : 1 } )
exit
5. Add this to VirtualHost of the site needing profiling (/etc/apache2/extra/httpd-vhosts.conf):
php_admin_value auto_prepend_file "/Sites/xhgui/external/header.php"
That's it. See it in browser:
http://www.xhgui.lh/
Leave a Reply