# Platform.sh

Blackfire has built-in support for [Platform.sh](https://platform.sh)projects. The integration is made simpler as Blackfire agent and probe are installed and enabled by default on all Platform.sh accounts.

Blackfire **server credentials** and the `.platform.app.yaml` file should be configured out of the box for Platform.sh [Obervability Suite](https://platform.sh/features/observability-suite/) customers. Those steps may then be ignored. Blackfire integration appears in the project settings in Platform.sh [console](https://docs.platform.sh/administration/web.html).

## Setting-Up Blackfire Credentials In Your Project

Set the Blackfire **server credentials** as environment variables (run this command from the root directory of your project):

> **Note**
>
> You may also use your [Platform.sh console](https://docs.platform.sh/administration/web/configure-environment.html#variables)

## Setting-Up Blackfire Client Credentials to trigger CLI Profiles

The **client credentials** are required to [trigger profiles with the CLI](../../profiling-cookbooks/profiling-http-via-cli) from your Platform.sh environments. In this case, set the **client credentials** as environment variables (run this command from the root directory of your project):

> **Warning**
>
> Recommended: To explicitly define which [environment](../../reference-guide/environments) the profile must be sent to, use the `--env=<ENV_UUID>` parameter.
>
> `v2.14.0+` of the [unified Agent and Client](../../up-and-running/update): when no target environment is specified, the Agent uses the `BLACKFIRE_SERVER_ID` environment variable to determine where to send the profile.
>
> When no target environment is specified or implicitly discovered, the profile is sent to the personal sandbox environment of the user whose [personal credentials](../../up-and-running/configuration/cli#cli-client-env-vars) (`BLACKFIRE_CLIENT_ID`and `BLACKFIRE_CLIENT_TOKEN`) were used. Only that user can then access the profile from [/my/profiles](../../my/profiles).
>
> To explicitly specify your personal sandbox environment, use `--env="My Environment"`

## Configuring Your App

The configuration of your application depends on its type.

**PHP Application**

Add the `blackfire` PHP extension to the `.platform.app.yaml` project file:

```yaml
runtime:
    extensions:
        - blackfire
```

**Python Application**

> **Note**
>
> Your application must have the [Blackfire Probe installed](../../docs/up-and-running/installation?action=install&mode=full&version=latest&mode=quick&location=local&os=debian&language=python#install-the-python-probe)as a `pip` dependency.

Update your `.platform.app.yaml` file to use the `blackfire-python` binary to start your webserver:

```yaml
# .platform.app.yaml
web:
    upstream:
        socket_family: unix
    # Commands are run once after deployment to start the application process.
    commands:
        # Replace "my_app.wsgi" by your actual WSGI script.
        start: "blackfire-python gunicorn -w 4 -b unix:$SOCKET my_app.wsgi:application"
```

## Develop on GitHub, Deploy to Platform.sh and Test on Blackfire

[Requires Production Plan](https://www.blackfire.io/pricing)

Here is a full video tutorial to get you started with the integration of the three services:

[platformsh-integration-tutorial](https://www.youtube-nocookie.com/embed/-5icUW9pUH8?rel=0&showinfo=0&modestbranding=1&autoplay=0)
