PHP agent installation: Non-standard PHP (advanced)

If you are using a non-standard PHP installation, follow this procedure to properly install New Relic. This is common in instances where the default installer does not find your PHP installation (for example: if you have self-compiled PHP or a self-contained PHP stack).

As part of the installation process, change the default application name to a meaningful name.

Requirements

Use the command line version of PHP (php -i) or look at the output of phpinfo() to determine:

  • The PHP extension version (20090626, 20100525, 20121212, 20131226, 20151012, or 20160303)
  • The extension or module installation directory
  • Whether or not your version of PHP has been compiled with ZTS (Zend Thread Safety) support

Using the command line newrelic-install script (recommended)

  1. Point New Relic at the right directory by using any of these options:

    Add your PHP location to your PATH

    The install script needs to be able to find your command line php or php-config. You can add the directory that contains those programs to your current PATH.

    Set the NR_INSTALL_PATH variable.

    This can be a colon-separated list of directories in which to look for PHP installations in addition to those in your PATH. These directories should contain php or php-config. For example:

    NR_INSTALL_PATH=/u/php/5.3/bin; export NR_INSTALL_PATH
    newrelic-install
            
    Set the NR_INSTALL_PHPLIST variable

    Optional: Use a colon-separated list to set the exact locations (directories) in which to search. This option will ignore PATH and NR_INSTALL_PATH. For example:

    NR_INSTALL_PHPLIST=/usr/local/bin:u/php/5.3/bin; export NR_INSTALL_PHPLIST
    newrelic-install
            
  2. Invoke the newrelic-install script from its directory. Depending on your server and your paths, the install script may find other versions of PHP on your system. Select your specific version from the list.

For more information, see PHP install script. Or, to resume your installation instructions, see New Relic for PHP.

Installing New Relic manually

If you do not want to use the install script, you can perform a fully manual installation. You will need to gather information about your PHP installation, as described above, and create and link or copy the files into place manually.

You can either review and obtain the appropriate values from your phpinfo() yourself, or you can load our manual installation script [ZIP] into your document root to automatically generate all the commands for your specific environment.

The manual installation script is the simpler method, and it can be reused to upgrade the PHP agent. It will also confirm a successful installation upon reload.

Using the manual installation script
  1. Download the Manual Installation Script [ZIP].
  2. Extract the nrmaninstall.php file to your document root. This will make it visible in a browser.
  3. Run the script by accessing that file in your browser at URL/nrmaninstall.php (for example: http://localhost/nrmaninstall.php).
  4. Copy and paste the custom instructions for your environment into your command line shell.
  5. Reload the nrmaninstall.php page in your browser to check for a successful installation.
Obtaining installation parameters from phpinfo()

If this does not work you can obtain the correct information from your phpinfo() and pass the appropriate settings to your system as environment variables.

phpinfo() Notes
PHPAPI This is labeled PHP Extension in the phpinfo() header.
ARCH This can be determined by executing file /path/to/php.
  • If you see a reference to ELF-32, then the ARCH is x86.
  • If you see a reference to ELF-64, then the ARCH is x64.
MODULEDIR This is labeled extension_dir in the PHP Core section.
PHPZTS To determine whether ZTS is compiled in, look for the Thread Safety setting at the top of the phpinfo() output.
  • If this is disabled, then PHPZTS is empty.
  • If this is enabled, then PHPZTS is the string -zts, which includes a leading hyphen as noted.
NRBASEDIR This is the base directory of the New Relic agent installation directory (/usr/lib/newrelic-php5 or the directory in which you extracted the tar file for tarball installations).

Use this information to execute the following commands to install the PHP module. Be sure to adjust the example's values to your actual settings.

    NRBASEDIR=/usr/lib/newrelic-php5; export NRBASEDIR
    MODULEDIR=/usr/lib/php/modules; export MODULEDIR
    ARCH=x64; export ARCH
    PHPAPI=20090626; export PHPAPI
    PHPZTS="-zts"; export PHPZTS
    rm -f $MODULEDIR/newrelic.so
    ln -s $NRBASEDIR/agent/$ARCH/newrelic-${PHPAPI}${PHPZTS}.so \
      $MODULEDIR/newrelic.so
    

The next step is configuration.

  1. Copy the $NRBASEDIR/scripts/newrelic.ini.template to the directory from where your PHP installation reads additional config files and rename it newrelic.ini.

    To determine the destination, look at your phpinfo() output for the item, called Scan this dir for additional .ini files. If the directory listed is (none), add settings from this file to your listed php config files (usually php.ini).

  2. Replace the license key setting in your newrelic.ini file with your license key. Also change any other sessions as needed (for example, newrelic.appname).
  3. Copy $NRBASEDIR/daemon/newrelic-daemon.$architecture to /usr/bin/newrelic-daemon.

    Depending on your system, $architecture will be either x86 or x64.

  4. Restart your dispatcher/webserver.
  5. Verify that your site is functioning properly. If it is not, remove newrelic.ini or the newrelic.so you created, and restart your dispatcher/webserver again to restore old operation.
  6. Examine your webserver/dispatcher (not newrelic) logfiles to help determine the issue. If you still need assistance, get support at support.newrelic.com.

Check that the agent is installed after the restart, by investigating the phpinfo() page for a newrelic section. If it appears the agent was succesfully installed, check your system to verify that two newrelic-daemon processes are runnning:

  • For RedHat based systems: ps -aef | grep newrelic-daemon
  • For Debian based systems: ps aux | grep newrelic-daemon

Wait for 3 to 5 minutes for results to arrive in your APM Overview page.

For more help

Join the discussion about PHP in the New Relic Online Technical Community! The Technical Community is a public platform to discuss and troubleshoot your New Relic toolset.

If you need additional help, get support at support.newrelic.com.