Help APM APM for PHP Install PHP Agent for Linux

Install PHP Agent for Linux

Install APM Insight PHP Agent

This installation process will only work on a Linux operating system. Refer here for Windows.  
  1. Recommended method of installation
  2. Install using script
  3. Instructions for manual installation
  4. Instructions to install in docker
  5. Automatically restart agent during service reboots

Recommended method:

  1. Log in to your Site24x7 account > APM > Add PHP for Linux
  2. Copy and execute the given script in the terminal. 
  3. Set preferred application name by changing the toggle button. By default, the name is set to PHP-application.
  4. Customize parameters as required and complete the installation.
  5. Restart your apache/fpm.nginx service to start monitoring.
  6. To view data, navigate to APM Insight > APM > Your application

Install using script

Use these instructions when you come across the following message while trying to install:

PHP is not found in PATH. Kindly install php or add php installation directory to PATH!

If PHP is managed by third-party applications, like cPanel/WHM, kindly refer to the manual installation steps below.
  1. Download the agent using the following command:
    wget https://staticdownloads.site24x7.com/apminsight/agents/agent_php.zip
    Verify the integrity of the downloaded agent using checksum validation. Learn more.
  2. Move the agent to /opt/ directory and extract the contents of the downloaded file. This will create a directory zpa/ under /opt/.
    sudo unzip -d /opt/ agent_php.zip
  3. Navigate to zpa/bin directory and execute the following command:
    cd /opt/zpa/bin sudo sh configure.sh
    Note:
    • licensekey is mandatory. Provide your Site24x7 license key in the code in the line above.
    • applicationname is the monitor name to be shown in Site24x7 console. It is optional, and by default, is set to PHP-Application.
  4. Restart your web servers. If you are running Apache, restart apache/httpd service. If you're running nginx/fpm based servers, restart the php-fpm services.
    • For Apache2 (Debian)
      sudo service apache2 restart
    • For Apache2 (RHEL/CentOS)
      sudo service httpd restart
    • For nginx/fpm based servers.
      sudo service php-fpm restart
  5. Once the agent is installed successfully, you can view the monitor in the Site24x7 Console under APM -> APM Insight -> Applications.

How to verify if the installation is successful:

After installation, go to terminal and execute the following command:

$ php -m | grep zpa

The output should contain zpa

Note:

The agent does not restart automatically during server reboots. To start, stop or restart the agent, use the following commands:

$ cd /opt/zpa/bin

#Start the agent
$ sh run.sh start

#Stop the agent
$ sh run.sh stop

#Restart the agent
$ sh run.sh restart
For systemd supported OS, use the following command to restart:
$ service zpdpsvc restart


Manual installation:

If PHP is installed using third-party managed services, like cPanel/WHM, or if the PHP path is not set properly during the installation, you might get the following message:

PHP is not found in PATH. Kindly install php or add php installation directory to PATH!

In these cases, you can retry the installation after setting the correct PHP directory in the PATH variable, or you can proceed to configure the agent manually, using these steps.

  1. Download the agent using the following command:
    wget https://staticdownloads.site24x7.com/apminsight/agents/agent_php.zip
    Verify the integrity of the downloaded agent using checksum validation. Learn more.
  2. Move the agent to /opt/ directory and extract the contents of the downloaded file. This will create a directory zpa/ under /opt/.
    sudo unzip -d /opt/ agent_php.zip
  3. Find your PHP API version, using the following command. There should be a corresponding zpa.so file in the /opt/zpa/libdirectory for the respective API version. Eg., zpa20131226.so for API version 20131226.
    php -i | grep "PHP API" 
    # Example output
    PHP API => 20131226
  4. Find your PHP's ini configuration path. This is the path where dynamically loaded extension configurations are added. Copy the /opt/zpa/bin/zpa.inito this location.
    php -i | grep "Scan this dir"
    # Example output
    # Scan this dir for additional .ini files => /opt/cpanel/ea-php56/root/etc/php.d/
    cp /opt/zpa/bin/zpa.ini /opt/cpanel/ea-php56/root/etc/php.d/zpa.ini
  5. Note: Use this step, only when the output in step 4 in this section is not configured. In case the ini configuration path is not set, the extensions must be configured in the php.ini file directly. Add the following line to php.ini near the end of the file.
    extension=zpa.so
  6. Find your PHP's extension directory. This is the path where extension libraries are loaded. Copy the respective zpa.so file for the API version obtained from step 3 in this section.
    php -i | grep "extension_dir"
    # Example output
    # extension_dir => /opt/cpanel/ea-php56/root/usr/lib64/php/modules
    cp /usr/lib/php/zpa20131226.so /opt/cpanel/ea-php56/root/usr/lib64/php/modules/zpa.so
  7. Restart your web servers. If you are running Apache, restart apache/httpd service. If you're running nginx/fpm based servers, restart the php-fpm services.
    # For Apache2 (Debian) sudo service apache2 restart
    # For Apache2 (RHEL/CentOS) sudo service httpd restart
    # For nginx/fpm based servers. sudo service php-fpm restart
  8. Verify if the agent is successfully loaded using the following command. The output should contain zpa.
    php -i | grep zpa
    #Example output
    #zpa
    #zpa.version => 3.0.2
    #zpa.date => 7 May 2021
    #zpa.capture_clirequest => 1 => 1
    #zpa.capture_httphost => 0 => 0
    #zpa.capture_phpself => 0 => 0
  9. To start communicating with Site24x7, add the Site24x7 license key to /opt/zpa/conf/apminsight.conf. Place the license key value in the line beginning with license.key=<Enter_license_key_here>
    ################### APM Insight Agent Configuration File ###################
    #
    license.key=<Enter_license_key_here>
    #
  10. Navigate to /opt/zpa/binand start the agent service, by executing the following command:
    cd /opt/zpa/bin
    sudo sh run.sh start
    # To verify the status
    # ps -ef | grep zpdp
    To make sure the agent is restarted during system reboots, you can register the agent as a service. Alternatively, you can use rc.local or cron task to ensure agent is started during system reboots.

Install in docker:

While creating container images, add these commands to the dockerfiles used for image creation as follows:

RUN cd /opt/ && wget
https://staticdownloads.site24x7.com/apminsight/agents/agent_php.zip
RUN unzip agent_php.zip
RUN cd /opt/zpa/bin && sh configure.sh<licensekey><app_name>
RUN sh run.sh start

Whenever the container is started, make sure zpdpsvc is restarted using the following command (under /opt/zpa/bin directory)

sh run.sh start

 

Was this document helpful?
Thanks for taking the time to share your feedback. We’ll use your feedback to improve our online help resources.

Help APM APM for PHP Install PHP Agent for Linux