Install Intaro Pinboard on Debian
Intaro Pinboard is a Web application that display statistics generated by Pinba. It ease the identification of PHP code consuming a high amount of resources.
This how-to is tested on:
- Debian 7.0 Wheezy
This how-to is tested with theses versions of Intaro Pinboard:
- 1.1
Prerequisite
This how-to needs:
- a2tools, a script easing Apache 2 server administration.
- a HTTP server with PHP, as described by Install PHP-FPM on Debian.
- a MySQL server, as described by Install and setup MySQL on Debian.
- mysql-tools, a script easing MySQL server administration on localhost (and MySQL server host, if other).
This how-to recommends:
- The Pinba extension for PHP, as described by Install the PHP extension Pinba on Debian.
Parameters
Provide the domain name where will be available the software:
DOMAIN="pinboard.domain.com"
Provide the MySQL server host:
MYSQL_HOST="localhost"
If the MySQL server is not local, the mysql-tools script will try to connect with MySQL client, or in case of connection failure, through SSH.
Provide the name of the SSL certificate to use (created by following Create a SSL / TLS certificate on Debian) (optionnal, recommended):
SSL_KEY_NAME="${DOMAIN}"
Security parameters
Provide a username to protect the application access (optional, recommended):
USER_NAME="admin"
Installation
Compute the installation path:
INSTALL_PATH="/opt/pinboard/${DOMAIN}"
Make sure that the parent folder exists:
command mkdir -p "$(command dirname "${INSTALL_PATH}")"
Environment preparation
Install the needed software:
command apt-get install php5-mysql php5-gd php5-cli git apg
Reload 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
Application installation
Download application latest version:
command git clone 'https://github.com/intaro/pinboard' "${INSTALL_PATH}"
Enter the source folder:
command pushd "${INSTALL_PATH}"
Install Composer:
command wget --quiet --output-document=- --no-check-certificate \
'https://getcomposer.org/installer' \
| command php
Install the PHP libraries needed by the application:
command php "${INSTALL_PATH}/composer.phar" install
Exit the source folder:
command popd
Database access configuration
Use mysql-tools to create the MySQL user allowed to access the "pinba" database:
MYSQL_PARAMS="$(command mysql-tools --server="${MYSQL_HOST}" --with-ssh \
--auto-hosts --database="pinba" --user-prefix="p" --adduser="${DOMAIN}")"
Fetch the created user parameters:
MYSQL_DB="$(echo "${MYSQL_PARAMS}" | command grep -e "^MYSQL_DB" \ | cut --delimiter="=" --fields="2-")" MYSQL_USER="$(echo "${MYSQL_PARAMS}" | command grep -e "^MYSQL_USER" \ | cut --delimiter="=" --fields="2-")" MYSQL_PASSWORD="$(echo "${MYSQL_PARAMS}" | command grep -e "^MYSQL_PASSWORD" \ | cut --delimiter="=" --fields="2-")" echo "${MYSQL_PARAMS}"
Application setup
Create the application configuration file:
command cp "${INSTALL_PATH}/config/parameters.yml.dist" "${INSTALL_PATH}/config/parameters.yml"
Adjust the Command folder permissions:
command chown www-data:www-data "${INSTALL_PATH}/src/Pinboard/Command"
Setup the database access:
command sed -i \
-e "s/host:.*$/host: ${MYSQL_HOST}/" \
-e "s/user:.*$/user: ${MYSQL_USER}/" \
-e "s/pass:.*$/pass: ${MYSQL_PASSWORD}/" \
"${INSTALL_PATH}/config/parameters.yml"
Initialize the database:
"${INSTALL_PATH}/console" migrations:migrate
Setup the data aggregation (the aggregation frequency must be the same as the "pinba_stats_history" option (15 minutes by default)):
command echo "*/15 * * * * www-data test -x '${INSTALL_PATH}/console' && ${INSTALL_PATH}/console aggregate > '/dev/null'" \
> "/etc/cron.d/pinboard-${DOMAIN//./-}"
Reload cron:
/etc/init.d/cron reload
Launch a first data aggregation:
command su www-data -c "${INSTALL_PATH}/console aggregate"
Hardening security
Create a random password for the user:
USER_PASSWORD="$(command apg -q -a 0 -n 1 -M NCL)"
Add the user, if needed:
if [ -n "${USER_NAME}" ]; then
command sed -i \
-e '/secure:/,/enable:/{s/enable:.*$/enable: true/}' \
"${INSTALL_PATH}/config/parameters.yml"
"${INSTALL_PATH}/console" add-user "${USER_NAME}" "${USER_PASSWORD}"
fi
If the system use PHP-FPM, install the needed fix:
if [ -x '/etc/init.d/php5-fpm' -a -n "${USER_NAME}" ]; then
command sed -i -e '/<\/IfModule>/i\
RewriteCond %{HTTP:Authorization} ^(.*)\
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]' \
"${INSTALL_PATH}/web/.htaccess"
fi
Print the connection parameters:
if [ -n "${USER_NAME}" ]; then
echo "URL: http://${DOMAIN}/
Username : ${USER_NAME}
Password : ${USER_PASSWORD}"
fi
Take note of the displayed informations.
Virtual Host setup
Setup the HTTP server virtual host :
if [ -n "${SSL_KEY_NAME}" -a -e "/etc/ssl/private/${SSL_KEY_NAME}.key" ]; then
command a2tools --overrides="All" --ssl="${SSL_KEY_NAME}" "${DOMAIN}" "${INSTALL_PATH}/web"
command a2tools --template='redirect' "${DOMAIN}" "https://${DOMAIN}/"
else
command a2tools --overrides="All" "${DOMAIN}" "${INSTALL_PATH}/web"
fi
The application is now available on the specified domain name with HTTP and HTTPS protocols if possible.
Automatic update
Install the daily automatic update script:
echo "#"'!'"/bin/bash
# Update ${DOMAIN} source code from Git.
test -x '/usr/bin/git' -a -d '${INSTALL_PATH}' && {
pushd '${INSTALL_PATH}' > '/dev/null'
command git pull --quiet > '/dev/null'
command chown www-data:www-data '${INSTALL_PATH}/src/Pinboard/Command'
command php '${INSTALL_PATH}/composer.phar' self-update > '/dev/null'
command php '${INSTALL_PATH}/composer.phar' update > '/dev/null'
command php '${INSTALL_PATH}/console' migrations:migrate <<< 'y' > '/dev/null'
popd > '/dev/null'
}" \
> "/etc/cron.daily/${DOMAIN}-update"
command chmod +x "/etc/cron.daily/${DOMAIN}-update"
Backups
Backup the installation with Backup Manager (see Install and setup Backup Manager on Debian) :
command backup-manager-tools add "${INSTALL_PATH}"
Don't forget to backup the database (see Install and setup MySQL on Debian).
Thanks
- Thanks to Intaro Pinboard (en) developers.