• Print
  • Share
  • Dark
    Light

PHP APM with Docker

  • Updated on 12 Nov 2018
  • 1 minute to read
  • Contributors

Setting up the Stackify PHP Profiler with Docker requires a few adjustments to the standard installation instructions found in the Getting Started guide.

Step 1

Install the Retrace monitoring agent on your server.

Follow the Linux Agent Install Guide with Docker Guide.

Step 2

Adjust docker container setup to include PHP Profiler Extension configuration.

Add stackify_php_docker.sh script to your dockerfile with the following contents:

#!/bin/bash
MAIN_INSTALL_PHP_APM_DIR="/usr/local/stackify/stackify-php-apm"
EXTENSION_DIR=`php -r 'echo ini_get("extension_dir");'`
PHP_MAJOR_VERSION=`php -r 'echo PHP_MAJOR_VERSION;'`
PHP_MINOR_VERSION=`php -r 'echo PHP_MINOR_VERSION;'`
PHP_ZTS_ENABLED=`php -r 'echo PHP_ZTS;'`
PHP_VERSION="${PHP_MAJOR_VERSION}.${PHP_MINOR_VERSION}";
if [ "$PHP_ZTS_ENABLED" == "1" ]; then
   PHP_VERSION="${PHP_VERSION}.zts";
fi
echo "Detected PHP ${PHP_VERSION} and extension directory: ${EXTENSION_DIR}"
EXTENSION_FILE="${MAIN_INSTALL_PHP_APM_DIR}/linux_32/stackify-${PHP_VERSION}.so"
if [ "`uname -m`" == "x86_64" ]; then
  EXTENSION_FILE="${MAIN_INSTALL_PHP_APM_DIR}/linux_64/stackify-${PHP_VERSION}.so"
fi
echo "Installing into $EXTENSION_DIR"
ln -s ${EXTENSION_FILE} ${EXTENSION_DIR}/stackify.so
ln -s ${MAIN_INSTALL_PHP_APM_DIR}/Stackify.php ${EXTENSION_DIR}/Stackify.php

This can be done many ways depending on your setup. For example, you may adjust the dockerfile to include and execute the script:

ADD stackify_php_docker.sh /
RUN ["chmod", "+x", "/stackify_php_docker.sh"]
RUN [ "/stackify_php_docker.sh" ]

Adjust the container's php.ini configuration to include the following.

[stackify]
extension=stackify.so
stackify.application_name=Test Application
stackify.environment_name=QA

This may be done many ways depending on your setup. For example, you may append the required values in the dockerfile.

RUN echo "[stackify]" >> /etc/php/7.0/apache2/php.ini && \
   echo "extension=stackify.so" >> /etc/php/7.0/apache2/php.ini && \
   echo "stackify.application_name=Test Application" >> /etc/php/7.0/apache2/php.ini && \
   echo "stackify.environment_name=QA" >> /etc/php/7.0/apache2/php.ini
  • We suggest naming your application name and specifying an environment name like Production, QA, etc.
  • The php.ini path will be unique to your specific setup. Be sure to update appropriately.

Start your PHP application as usual. The Linux Agent installed on the host will handle processing your application via the shared volume (/usr/local/stackify) setup earlier.

Verify

Start up your PHP application container and make requests. You can then verify results in the Retrace dashboard.

Additional Guides