Install PHP agent on a Lando application server
Before you begin
Create a working application and
.lando.ymlfile using supported technologies.
Steps
Important
Never place the contrast.env file in the application's webroot directory.
In your project's root directory, under the
appserverservice section of the.lando.yamlfile, install the Contrast agent in the default service by adding this configuration:services: appserver: build_as_root: - curl https://pkg.contrastsecurity.com/api/gpg/key/public | apt-key add - - echo "deb https://pkg.contrastsecurity.com/debian-public/ $(sed -rne 's/^VERSION_CODENAME=(.*)$/\1/p' /etc/*ease) contrast" \ | tee /etc/apt/sources.list.d/contrast.list - echo "deb https://pkg.contrastsecurity.com/debian-public/ all contrast" | tee -a /etc/apt/sources.list.d/contrast.list - apt-get update && apt-get install contrast-php-agent - contrast-php-util enable-agent env_file: - /path/to/contrast.envThe environment variables are set in the
contrast.envfile for either an agent token or a legacy configuration. The following variables you can set are proposed changes for your reference.Agent Token: In a
contrast.envfile outside thewebrootof your project, enable the connection to Contrast by adding the minimum agent configuration:CONTRAST__API__TOKEN={token value} CONTRAST__ASSESS__ENABLE=true CONTRAST__SERVER__NAME={yourServerName} CONTRAST__AGENT__LOGGER__PATH=stdoutIf your agent configuration refers to both the legacy settings and the agent token, (in environment variables or the YAML file), the legacy settings take precedence. Remove references to the legacy settings to use just the agent token value.
Legacy settings: If you are using a PHP agent version earlier than 1.34.0, set these variables:
CONTRAST__API__URL={contrastURL} CONTRAST__API__API_KEY={apiKey} CONTRAST__API__SERVICE_KEY={serviceKey} CONTRAST__API__USER_NAME={contrastAgentUserName} CONTRAST__ASSESS__ENABLE=true CONTRAST__SERVER__NAME={yourServerName} CONTRAST__AGENT__LOGGER__PATH=stdout
Notes
Configuring a name for the
server.nameproperty prevents the agent from creating a new server entry in the Contrast web interface when the server restarts.The
agent.logger.pathproperty is set tostdoutto avoid printing agent logs to thewebrootdirectory. The Contrast agent logs are available using this configuration by running thelando logs -s appservercommand.You can use the Contrast agent configuration editor to verify and export the agent configuration as environment variables.
To enable the Contrast agent, run the
lando startcommand (if not used previously) or thelando rebuild -ycommand.