phpIPAM and tideways xhprof php profiling - GaryAllan/phpipam GitHub Wiki
Introduction
This guide details the steps required to install and configure phpIPAM php profiling using the tideways php profiling module and xhprof web interface. This guide is based on the following assumptions.
- Installation is on a non-public development server/VM using a copy of a production database.
- The environment is Ubuntu 16.04 LTS (x64) desktop.
- Apache/PHP/MySQL are installed locally using Apache virtual hosts (127.0.0.1).
Install and configure phpIPAM and the tideways php module
Update Ubuntu 14.04 LTS.
sudo apt-get update
sudo apt-get upgrade
Install pre-requisite software packages.
sudo apt-get install php php-cli php-dev php-gd php-ldap php-mcrypt php-json php-gettext php-mbstring php-mysql
sudo apt-get install libapache2-mod-php
sudo apt-get install mariadb-server
sudo apt-get install git nano graphviz
sudo apt-get install libcurl4-openssl-dev libpcre3-dev
Download and install the phpIPAM git repository.
cd ~
git clone https://github.com/phpipam/phpipam.git
cd phpipam
git submodule update --init --recursive
sudo ln -s ~/phpipam /var/www/phpipam
Create the MySQL database
sudo mysql
MariaDB [(none)]> CREATE DATABASE phpipam;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON phpipam.* TO 'phpipam'@'localhost' IDENTIFIED BY 'phpipamadmin';
MariaDB [(none)]> FLUSH PRIVILEGES;
Import the DB SCHEMA.
cd ~/phpipam
mysql -u phpipam -p phpipam <db/SCHEMA.sql
Enter password: phpipamadmin
Copy and edit the phpIPAM config.php file as required...
cd ~/phpipam
cp config.dist.php config.php
nano config.php
Download, configure and install the tideways php extension repository.
cd ~
git clone https://github.com/tideways/php-profiler-extension.git tideways
cd ~/tideways
phpize
./configure --with-php-config=/usr/bin/php-config
make
sudo make install
Configure php to load the tideways php extension.
sudo tee /etc/php/7.0/mods-available/tideways.ini <<EOF
; Enable tideways extension module
extension=tideways.so
tideways.auto_prepend_library=0
EOF
cd /etc/php/7.0/apache2/conf.d/
sudo ln -s /etc/php/7.0/mods-available/tideways.ini 90-tideways.ini
cd /etc/php/7.0/cli/conf.d
sudo ln -s /etc/php/7.0/mods-available/tideways.ini 90-tideways.ini
Verify that the tideways php module is successfully installed.
php -m | grep tideways
Configure xhprof
Download the xhprof software. We are only interested in the WebGUI folders.
cd ~
git clone https://github.com/phacility/xhprof.git xhprof
Copy the Web GUI files into the /var/www/xhprof folder.
sudo mkdir /var/www/xhprof
sudo cp -r ~/xhprof/xhprof_html/ /var/www/xhprof/
sudo cp -r ~/xhprof/xhprof_lib/ /var/www/xhprof/
Create the tideways header.php file.
sudo nano /var/www/xhprof/header.php
<?php
if ( extension_loaded('tideways') ) {
include_once dirname(__FILE__) . '/xhprof_lib/utils/xhprof_lib.php';
include_once dirname(__FILE__) . '/xhprof_lib/utils/xhprof_runs.php';
tideways_enable(TIDEWAYS_FLAGS_MEMORY);
}
Create the tideways footer.php file.
sudo nano /var/www/xhprof/footer.php
<?php
if ( extension_loaded('tideways') ) {
$url = 'http://xhprof/index.php';
$namespace = preg_replace('/\..*/', '', $_SERVER['HTTP_HOST']);
$xhprof_data = tideways_disable();
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, $namespace);
$profiler_url = sprintf('%s?run=%s&source=%s', $url, $run_id, $namespace);
echo '<a href="'. $profiler_url .'" target="_blank">Profiler output</a>';
}
Configure Apache
Update the /etc/hosts file by running "sudo nano /etc/hosts" and add the following lines.
127.0.0.1 phpipam
127.0.0.1 xhprof
Create the VirtualHost definition for xhprof.
sudo tee /etc/apache2/sites-available/xhprof.conf <<EOF
# xhprof VirtualHost definition
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName xhprof
DocumentRoot /var/www/xhprof/xhprof_html
</VirtualHost>
<Directory "/var/www/xhprof/xhprof_html">
AllowOverride All
# Allow open access:
Require all granted
</Directory>
EOF
Configure the VirtualHost definition for phpIPAM.
sudo tee /etc/apache2/sites-available/phpipam.conf <<EOF
# phpIPAM VirtualHost definition
<VirtualHost *:80>
ServerName phpipam
DocumentRoot /var/www/phpipam
php_value auto_prepend_file /var/www/xhprof/header.php
php_value auto_append_file /var/www/xhprof/footer.php
</VirtualHost>
<Directory "/var/www/phpipam">
AllowOverride All
# Allow open access:
Require all granted
</Directory>
EOF
Delete the default website and enable the phpIPAM and xhprof sites.
cd /etc/apache2/sites-enabled/
sudo rm 000-default.conf
sudo ln -s /etc/apache2/sites-available/phpipam.conf 000-phpipam.conf
sudo ln -s /etc/apache2/sites-available/xhprof.conf 001-xhprof.conf
Enable mod-rewrite.
cd /etc/apache2/mods-enabled/
sudo ln -s /etc/apache2/mods-available/rewrite.load
Restart Apache.
sudo apachectl graceful
Verify profiling is active
Open http://phpipam in firefox. If profiling is active the "Profiler output" links is visible.