# Installation

Learn how to integrate Croct into your PHP project.

The following guide gives you a step-by-step overview of how to install and initialize the SDK in your project.

> **Speed up your integration!**
>
> The CLI can fully automate the integration process for you. Check out the [integration guide](/reference/sdk/php/integration) to get started faster.

## Install the SDK \[#install]

Install the SDK using [Composer](https://getcomposer.org):

```sh
composer require croct/plug-php
```

The SDK works with any [PSR-18 HTTP client](https://www.php-fig.org/psr/psr-18/) and [PSR-17 factories](https://www.php-fig.org/psr/psr-17/), which it discovers automatically. If your project does not have a compatible implementation yet, install one:

```sh
composer require guzzlehttp/guzzle nyholm/psr7
```

## Initialize the SDK \[#initialize]

Add your credentials to a `.env` file in your project root:

**.env**

```bash
CROCT_APP_ID=<APPLICATION_ID>
CROCT_API_KEY=<API_KEY>
```

You can find the application ID and create an API key on the [Integration page](https://app.croct.com/redirect/organizations/-organization-/workspaces/-workspace-/applications/-application-/integration) of your application.

Then set up the SDK and hand off to the browser so personalization continues transparently on the client side:

**index.php**

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

$croct = Croct::fromDotenv();
$content = $croct->fetchContent('home-banner')->getContent();
Croct::emitCookies();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>My application</title>
</head>
<body>
    <h1><?= $content['headline'] ?></h1>
    <p><?= $content['tagline'] ?></p>

    <script src="https://cdn.croct.io/js/v1/lib/plug.js"></script>
    <script>croct.plug(<?= json_encode($croct->getPlugOptions()) ?>);</script>
</body>
</html>
```

The [`fromDotenv`](api/core/croct/from-dotenv) factory reads the credentials from your `.env` file and uses a cookie-based session store. Calling [`emitCookies`](api/core/croct/emit-cookies) writes the session cookies before any output, while [`getPlugOptions`](api/core/plug/get-plug-options) returns the configuration the [JavaScript SDK](/reference/sdk/javascript) needs to work transparently with the same session. For more details, see [Client-side setup](client-side-setup).

## Check your integration \[#check]

If you open your application now, it should start sending events.

To check if your integration is working, go to the [Integration page](https://app.croct.com/redirect/organizations/-organization-/workspaces/-workspace-/applications/-application-/integration) of your application.

![Integration status](/assets/reference/sdk/integration-status.png)

When working correctly, you should see a green bullet next to the **Status** label saying **"Received traffic in the past 24 hours"**. If you still do not see this message after a few minutes, see the [Troubleshooting](troubleshooting) reference.

## Explore

- [PHP SDK](https://github.com/croct-tech/plug-php): Explore and contribute to the SDK development on GitHub.
- [Troubleshooting](troubleshooting): Identify and resolve issues with your integration.
