Skip to main content

Install PHP agent in a pipeline

Using the Agent Wizard is the simplest way to deploy a new agent by selecting Language-specific > PHP > Install in a pipeline.

Select the installation method

  1. Under Select method to deploy with pipelines, select GitHub or Bitbucket.

  2. Under Select installation method, select Debian or RPM.

Install the agent for Debian

  1. Add the following step to your GitHub Action:

    - name: Install Agent  
      shell: bash  
      run: |    
        curl -fsSL https://pkg.contrastsecurity.com/api/gpg/key/public | sudo gpg --dearmor -o /usr/share/keyrings/contrast-keyring.pgp    
        echo "deb [signed-by=/usr/share/keyrings/contrast-keyring.pgp] https://pkg.contrastsecurity.com/debian-public/ all contrast" | sudo tee -a /etc/apt/sources.list.d/contrast.list    
        sudo apt-get update && sudo apt-get install -y contrast-php-agent
        echo "extension=/usr/local/lib/contrast/php/contrast.so" | sudo tee -a "$(php-config --ini-path)/php.ini"
  2. Add the following to the step running your application:

    env:
       CONTRAST__API__TOKEN: ${{ secrets.ContrastAPIToken }}
       CONTRAST__APPLICATION__NAME: ${{ secrets.ContrastApplicationName }}
       CONTRAST__APPLICATION__METADATA: ${{ secrets.ContrastApplicationMetadata }}

Install the agent for Red Hat Package Manager (RPM)

  1. Add the following step to your GitHub Action:

    - name: Install Agent  
      shell: bash  
      run: |    
        sudo rpm --import https://pkg.contrastsecurity.com/api/gpg/key/public    
        sudo tee /etc/yum.repos.d/contrast.repo <<-"EOF"    
        [contrast]    
        name=Contrast redhat-$releasever repo    
        baseurl=https://pkg.contrastsecurity.com/rpm-public/redhat-$releasever/    
        gpgcheck=0    
        enabled=1    
        gpgkey=https://pkg.contrastsecurity.com/api/gpg/key/public    
        repo_gpgcheck=1    
        EOF    
        sudo yum install -y contrast-php-agent    
        echo "extension=/usr/local/lib/contrast/php/contrast.so" | sudo tee -a "$(php-config --ini-path)/php.ini"
  2. Add the following to the step running your application:

    env:
       CONTRAST__API__TOKEN: ${{ secrets.ContrastAPIToken }}
       CONTRAST__APPLICATION__NAME: ${{ secrets.ContrastApplicationName }}
       CONTRAST__APPLICATION__METADATA: ${{ secrets.ContrastApplicationMetadata }}

Configure the agent

Configure the PHP agent.

A connection token is the recommended method. Set CONTRAST__API__TOKEN in the environment where you run your application.

Verify the agent deployment

Interact with your application as you normally would. For example, interact with your application's web interface or send API commands.

  1. In the Agent Wizard, select View agent activity to verify that your agent appears in the agents list.

  2. Verify that you see the name of your application in the applications list.

    • In Northstar, select Applications from the left navigation.

    • In Contrast, select Applications from the header.

  3. Verify that you see the name of your local server in the servers list.

    • In Northstar, select Servers from the left navigation.

    • In Contrast, select Servers from the header.