Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

johncarter's avatar

Meilisearch & Scout: "Authorization header is missing"

I have provisioned 2 servers on Forge, one an App server and the other a Meilisearch server.

When running the following scout index command on the App server: php artisan scout:import "App\Models\User"

I get an error stating the following:

MeiliSearch\Exceptions\ApiException 

The Authorization header is missing. It must use the bearer authorization method.

After reading the Meilisearch documentation, I can see that "requested resources are protected with an API key, that was not provided in the request header."

Okay, so just to confirm my steps to get to this point:

  1. Provision App server in Forge
  2. Provision Meilisearch server in Forge
  3. Put a tick in the Networking > "Can Connect To" on both servers
  4. Added my private Meilisearch IP as the MEILISEARCH_HOST=http://123.456.789:7700 in my app's .env file
  5. I have also tried three different MEILISEARCH_KEYs: the master key and both API keys that are shown in Forge's Meilisearch control panel under Meilisearch > API Keys, clearing config cache after every attempt.
  6. Then running php artisan scout:import "App\Models\User" after each attempt.

All versions of the MEILISEARCH_KEY result in the same error.

Using Tinker

I then have tried to manually connect to the Meilisearch server using php artisan tinker on the app server: $client = new MeiliSearch\Client('http://123.456.789:7700', 'TRIED_MANUALLY_ADDING_API_KEYS_AND_MASTER_KEYS_ON_SEPERATE_ATTEMPTS');

The $clients always get created but when I run $client->index('foo')->search('bar') on the client, I get the same MeiliSearch\Exceptions\ApiException with message 'The Authorization header is missing. It must use the bearer authorization method.'

Can anyone shed any light on why this is happening? I have dug into some source code and read the Meilisearch docs but I don't understand what part I have missed.

0 likes
6 replies
johncarter's avatar
johncarter
OP
Best Answer
Level 3

This was cured by composer update to bump meilisearch/meilisearch-php from 0.20.0 -> 0.21.0

3 likes
aureliee123's avatar

i'm having the same issue tried using composer update but same problem

rishabk's avatar

UPDATE: make sure you read the upgrade guide, else it might render your data useless & you might need to downgrade the engine/host version to get it working. https://docs.meilisearch.com/learn/advanced/updating.html https://docs.meilisearch.com/learn/advanced/snapshots_vs_dumps.html

@aureliee123 you need update the sdk package in composer.json to a version compatible with the meilisearch host. check github releases page for compatiblity details.

for meilisearch host 0.26.x, update composer value

"meilisearch/meilisearch-php": "^0.23.0"

then run:

composer update meilisearch/meilisearch-php    
clara's avatar

To those finding this via google (like me) this can also be caused by using http instead of https when there is a redirect in place

2 likes

Please or to participate in this conversation.