> ## Documentation Index
> Fetch the complete documentation index at: https://www.meilisearch.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP quick start

> Get started with Meilisearch using the PHP SDK in 5 minutes.

This guide walks you through setting up Meilisearch with PHP.

## Prerequisites

* PHP 7.4 or higher
* Composer
* A Meilisearch instance ([Cloud](https://cloud.meilisearch.com) or [self-hosted](https://www.meilisearch.com/docs/resources/self_hosting/getting_started/quick_start.md))

## 1. Install the SDK

```bash theme={null}
composer require meilisearch/meilisearch-php
```

## 2. Connect to Meilisearch

```php theme={null}
<?php

require_once __DIR__ . '/vendor/autoload.php';

use Meilisearch\Client;

$client = new Client(
    getenv('MEILISEARCH_URL'),
    getenv('MEILISEARCH_KEY')
);
```

> [!NOTE]
>
> **Set your environment variables:**
>
> ```bash theme={null}
> export MEILISEARCH_URL="https://your-instance.meilisearch.io"  # or http://localhost:7700
> export MEILISEARCH_KEY="your_api_key"
> ```
>
> [Get a free Cloud instance →](https://cloud.meilisearch.com)

## 3. Add documents

```php theme={null}
$movies = [
    ['id' => 1, 'title' => 'The Matrix', 'genres' => ['Action', 'Sci-Fi'], 'year' => 1999],
    ['id' => 2, 'title' => 'Inception', 'genres' => ['Action', 'Thriller'], 'year' => 2010],
    ['id' => 3, 'title' => 'Interstellar', 'genres' => ['Drama', 'Sci-Fi'], 'year' => 2014]
];

// Add documents to the 'movies' index
$task = $client->index('movies')->addDocuments($movies);

// Wait for indexing to complete
$client->waitForTask($task['taskUid']);
```

## 4. Search

```php theme={null}
$results = $client->index('movies')->search('matrix');

print_r($results->getHits());
// [['id' => 1, 'title' => 'The Matrix', 'genres' => ['Action', 'Sci-Fi'], 'year' => 1999]]
```

## 5. Search with filters

First, configure filterable attributes:

```php theme={null}
$client->index('movies')->updateFilterableAttributes(['genres', 'year']);
```

Then search with filters:

```php theme={null}
$results = $client->index('movies')->search('', [
    'filter' => 'genres = "Sci-Fi" AND year > 2000'
]);
```

## Full example

```php theme={null}
<?php

require_once __DIR__ . '/vendor/autoload.php';

use Meilisearch\Client;

$client = new Client(
    getenv('MEILISEARCH_URL'),
    getenv('MEILISEARCH_KEY')
);

// Add documents
$movies = [
    ['id' => 1, 'title' => 'The Matrix', 'genres' => ['Action', 'Sci-Fi'], 'year' => 1999],
    ['id' => 2, 'title' => 'Inception', 'genres' => ['Action', 'Thriller'], 'year' => 2010],
    ['id' => 3, 'title' => 'Interstellar', 'genres' => ['Drama', 'Sci-Fi'], 'year' => 2014]
];

$task = $client->index('movies')->addDocuments($movies);
$client->waitForTask($task['taskUid']);

// Search
$results = $client->index('movies')->search('inter');
print_r($results->getHits());
```

## Laravel integration

For Laravel applications, use Laravel Scout with the Meilisearch driver:

```bash theme={null}
composer require laravel/scout
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
```

Configure in your `.env`:

```env theme={null}
SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=https://your-instance.meilisearch.io
MEILISEARCH_KEY=your_api_key
```

Scout also supports [semantic and hybrid search](https://www.meilisearch.com/docs/getting_started/frameworks/laravel.md#embedders-for-semantic-and-hybrid-search) with Meilisearch. [See the full Laravel Scout guide →](https://www.meilisearch.com/docs/getting_started/frameworks/laravel.md)

## Next steps

> [card] [Laravel Scout](https://www.meilisearch.com/docs/getting_started/frameworks/laravel.md)
>
> Full Laravel integration guide

> [card] [Full-text search](https://www.meilisearch.com/docs/capabilities/full_text_search/relevancy/relevancy.md)
>
> Configure ranking and relevancy

> [card] [Filtering](https://www.meilisearch.com/docs/capabilities/filtering_sorting_faceting/getting_started.md)
>
> Add filters and facets

> [card] [API reference](https://www.meilisearch.com/docs/reference/api/search/search-with-post.md)
>
> Explore all search parameters

## Resources

* [meilisearch-php on GitHub](https://github.com/meilisearch/meilisearch-php)
* [SDK documentation](https://github.com/meilisearch/meilisearch-php#readme)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.