You are here: Home / Debian GNU/Linux / Servers / PHP / Install the Pinba PHP extension on Debian

Install the Pinba PHP extension on Debian

by Pierre-Yves Landuré last modified Aug 16, 2018 11:03

Pinba is a PHP extension gathering performance informations on the web applications hosted on the server using it.

This howto is tested on:

  • Debian 7.0 Wheezy

Prerequisite

This howto needs:

Parameters

Provide the hostname of the MySQL server:

MYSQL_HOST="localhost"

Installation

Detect PHP extension configuration path:

MODS_CONF_PATH='/etc/php5/conf.d'
test -d '/etc/php5/mods-available' \
  && MODS_CONF_PATH='/etc/php5/mods-available'

Environment preparation

Install the needed software:

command apt-get install build-essential libprotobuf-dev libprotobuf-lite7 \
libprotobuf7 protobuf-compiler php5-dev re2c

Software installation

Download the sources:

command git clone 'https://github.com/tony2001/pinba_extension' '/tmp/pinba_extension'

Go to the sources folder:

command pushd '/tmp/pinba_extension'

Prepare the build of the PHP extension:

command phpize

Configure the sources:

./configure

Build the extension:

command make

Install the extension:

command make install

Quit the source folder:

command popd

Delete the sources:

command rm -r '/tmp/pinba_extension'

Extension configuration

Detect the IP address of the MySQL host:

MYSQL_IP="$(command dig +short "${MYSQL_HOST}")"

Load the PHP extension:

echo '; configuration for php Pinba module
; priority=20
extension=pinba.so' > "${MODS_CONF_PATH}/pinba.ini"
test -n "$(command -v php5enmod)" && command php5enmod 'pinba'

Setup PHP to use the extension:

echo "; User configuration for php Pinba module
; priority=50
pinba.enabled=1
pinba.server=${MYSQL_IP}:30002" > "${MODS_CONF_PATH}/pinba-config.ini"
test -n "$(command -v php5enmod)" && command php5enmod 'pinba-config/50'

Create the prepend.php file if it does not exists:

if [ ! -e '/etc/php5/prepend.php' ]; then
command echo '<?php
// This file is prepended at each PHP script.' \
> '/etc/php5/prepend.php'
fi

Setup PHP to pass the served URL to Pinba:

command echo "if (isset(\$_SERVER['REQUEST_URI']) && function_exists('pinba_script_name_set')) pinba_script_name_set(\$_SERVER['REQUEST_URI']);" \
>> '/etc/php5/prepend.php'

Setup PHP to load the prepend.php file at the start of each served request:

command echo "; Load PHP code at startup.
auto_prepend_file=/etc/php5/prepend.php" \
> "${MODS_CONF_PATH}/prepend-code.ini"
test -n "$(command -v php5enmod)" && command php5enmod 'prepend-code/50'

Reload the PHP configuration:

test -x /etc/init.d/php5-fpm && /etc/init.d/php5-fpm force-reload
test -x /etc/init.d/apache2 && /etc/init.d/apache2 force-reload
test -x /etc/init.d/lighttpd && /etc/init.d/lighttpd force-reload
test -x /etc/init.d/nginx && /etc/init.d/nginx force-reload

Finalization

This howto recommends:

Thanks