Install PHP agent in a container
Using the Agent Wizard is the simplest way to deploy a new agent by selecting Language-specific > PHP > Install in a container. Installing the PHP agent in a container to AWS Fargate is also supported.
Select method to deploy
Select Dockerfile or Kubernetes.
Build Dockerfile image with agent
Under select method to deploy with containers.
Select Dockerfile, and add the following to the Dockerfile:
RUN mkdir -p /usr/local/lib/contrast/php COPY --from=contrast/agent-php:latest /contrast /usr/local/lib/contrast/php/ RUN echo "extension=/usr/local/lib/contrast/php/contrast.so" >> $(php-config --ini-path)/php.ini
The agent files in this image are built for glibc and work on Debian, Ubuntu, and Red Hat based images. For an Alpine-based image, install the agent with the APK method.
Build the image:
docker build -t my-app-with-contrast .
For Kubernetes (Linux only)
Under Select method to deploy with containers, select Kubernetes.
Under Select method to configure agent operator, select Helm charts or Manifest.
For Helm:
Under Download and set up the values file, copy the code displayed in the wizard to create a values file.
Skip this step if you already have the operator installed.
Under Install and deploy Helm chart, run the Helm commands in the wizard.
Skip this step if you already have the operator installed.
Under Label namespaces, run the command displayed to label your namespaces to add AgentInjectors.
Under Label deployments, follow the wizard steps and run the commands to label your deployments.
For Manifest:
Under Install operator, run the commands displayed in the wizard to install the Contrast agent operator.
Skip this step if you already have the operator installed.
Under Configure operator, follow the wizard steps to deploy the secret, connect your cluster, and apply the configuration.
Skip this step if you already have the operator configured.
Under Configure Injector, copy or download the YAML file, run the
kubectl applycommand displayed in the wizard, and then wait for the command to complete.Under Label namespaces, run the command displayed to label your namespaces to add AgentInjectors.
Under Label deployments, follow the wizard steps and run the commands to label your deployments.
Configure agent (optional): Copy the code to set agent settings once for every injected workload in the namespaces selected. The operator turns the yaml block into environment variables on the pod.
If your application runs on PHP-FPM, set
clear_envtonoin your pool configuration. See PHP agent supported technologies.
Configure the agent
A connection token is the recommended method.
For a Dockerfile install, a connection token is the recommended method. Set
CONTRAST__API__TOKENin the environment where you run your application. You can also use other environment variables or the PHP YAML template.For a Kubernetes install, the operator uses the connection details from the secret and
ClusterAgentConnectionthat you created in the Configure operator step. Use the optional Configure the PHP agent step to set other agent settings for your workloads.
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.
In the Agent Wizard, select View agent activity to verify that your agent appears in the agents list.
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.
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.