# fromEnvironment

Learn how to create the SDK from environment variables.

This static factory method creates an SDK instance from the `CROCT_*` environment variables, so you do not have to hard-code credentials.

## Signature

This method has the following signature:

```php
public static function fromEnvironment(?IdentityStore $storage = null): self
```

This method returns a configured SDK instance.

## Example

Here is a basic example of how to use this method:

```php
<?php
use Croct\Plug\Croct;

$croct = Croct::fromEnvironment();
```

## Environment variables

The method reads the following variables:

| Variable                  | Required | Description                                 |
| ------------------------- | -------- | ------------------------------------------- |
| `CROCT_APP_ID`            | Yes      | The ID of the application.                  |
| `CROCT_API_KEY`           | Yes      | The API key used to authenticate requests.  |
| `CROCT_TOKEN_DURATION`    | No       | The lifetime of the user token, in seconds. |
| `CROCT_BASE_ENDPOINT_URL` | No       | The base URL to use for the API calls.      |

## Parameters

The following list describes the supported parameters:

- `storage`: [`CookieStorage`](/reference/sdk/php/api/storage/cookie-storage) (optional) (default: null)

  The storage that persists the visitor session.

  The default is `null`, which uses a cookie-based store.
