# Getting Started

## Setup

The official PHP SDK for Stream covers Chat, Video, Moderation, and Feeds.

|           |                                                                                                          |
| --------- | -------------------------------------------------------------------------------------------------------- |
| GitHub    | [github.com/GetStream/getstream-php](https://github.com/GetStream/getstream-php)                         |
| Packagist | [packagist.org/packages/getstream/getstream-php](https://packagist.org/packages/getstream/getstream-php) |

Install the SDK:

```bash
composer require getstream/getstream-php
```

Initialize the client with your API key and secret (available on the [Dashboard](https://dashboard.getstream.io/)):

```php
use GetStream\ChatClient;

$client = new ChatClient("your-api-key", "your-api-secret");
```

Or load credentials from environment variables (`STREAM_API_KEY`, `STREAM_API_SECRET`) or a `.env` file:

```php
use GetStream\ClientBuilder;

$client = ClientBuilder::fromEnv()->buildChatClient();
```

## Server-side Token

Your backend generates a user token that the client SDKs use to authenticate. A typical place to issue this token is during login or registration.

```php
$token = $client->createUserToken("user-id");
// return the token to the client app
```

## Making Your First API Call

Create a user, open a channel, and send a message:

```php
use GetStream\GeneratedModels as Models;

// Upsert a user
$client->updateUsers(new Models\UpdateUsersRequest(
    users: ["john" => new Models\UserRequest(
        id: "john",
        name: "John",
    )],
));

// Create or join a channel
$client->getOrCreateChannel("messaging", "hello-world",
    new Models\ChannelGetOrCreateRequest(
        data: new Models\ChannelInput(
            createdByID: "john",
        ),
    )
);

// Send a message
$client->sendMessage("messaging", "hello-world",
    new Models\SendMessageRequest(
        message: new Models\MessageRequest(
            text: "Hello, Stream!",
            userID: "john",
        ),
    )
);
```


---

This page was last updated at 2026-04-10T16:29:34.235Z.

For the most recent version of this documentation, visit [https://getstream.io/chat/docs/php/](https://getstream.io/chat/docs/php/).