# fromDotenv

Learn how to create the SDK from a .env file.

This static factory method creates an SDK instance from a `.env` file, the simplest way to get started.

It reads the credentials from the `CROCT_*` variables in the `.env` file, falling back to the process environment, and uses a cookie-based session store, so there is nothing to wire up.

## Signature

This method has the following signature:

```php
public static function fromDotenv(?string $directory = null, ?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::fromDotenv();
```

## 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:

- `directory`: `string` (optional) (default: null)

  The directory containing the `.env` file.

  The default is `null`, which uses the current working directory.

- `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.
