Posts Learn Components Snippets Categories Tags Tools new About
/

How to Deploy MeiliSearch on Laravel Forge

Learn how to deploy MeiliSearch on Larave Forge for your production Laravel application to have blazing fast search speed and more typo friendly

4 months ago

10 mins read

1033 views

In this post, you'll learn how to deploy MeiliSearch to production with Laravel Forge in easy-to-follow steps. Without too much introduction, let's get started and get it up and running.

What is MeiliSearch?


MeiliSearch, it's the "Next-generation search API" which is just like Algolia but it's open-source and free to use. By default, MeiliSearch is blazing fast, tolerant to typos, synonymous, comes with filterings, language support, and more.

What is Laravel Forge?


Forge allows you to painlessly create and manage PHP servers which include MySQL, Redis, Memcached, database backups, and everything else you need to run robust, modern Laravel applications.

Laravel Forge Server Types


At the time of this writing, Laravel Forge support 7 types of server and below you can see the full breakdown of what is offered by each server type. To run MeiliSearch, they have a dedicated "MeiliSearch Server" and everything that's necessary to run and operate MeiliSearch is managed automatically by Laravel Forge, so you don't have to worry about future updates and more.
Laravel Forge Server Types

Do note that by default you will need to have a server connected to Laravel Forge which you can do so by adding the server by pressing any of the providers below. In this case, Vultr and Hetzner are ready to add a new server.
Laravel Forge Add Provider

Step 1: Create Server


Once you have set up a provider create a new server and add the credentials as follows. Make sure to save the sudo password and meilisearch password somewhere safe.
Create a New MeiliSearch Server on Laravel Forge

Do note that the server will take about 10 minutes to provision. Grab your coffee in the mean time ☕️
Laravel Forge Initializing MeiliSearch Server

The site will be called "default" and you don't have to change the name, if you do then you can change the name from the "meta" tab within the "default" site.
Laravel Forge Default Site


Step 2: Retrieve the API Keys from the MeiliSearch Sidebar


To retrieve the Public and Private Key you can access it by providing the "Master Password" from the "API Keys" page below.
MeiliSearch API Keys

Pressing "Reveal" will show you the "private" and "public" key like below.
MeiliSearch Private and Public Key

Step 3: Update the Server Network (MeiliSearch-Server)


To allow your MeiliSearch server to connect to other Laravel Forge servers, you have to tick "Can Connect To" from the Network tab.
Allow MeiliSearch server to be accessible by other Laravel Forge app server

Step 4: Update the Server Network (Laravel App Server)


The next part is to update the Server Network for your Laravel App Server by ticking the "Can Connect To".
Allow Laravel Forge app server to be accessible by MeiliSearch server

Step 5: Update Laravel Forge Site Environment


Once the connection is made you will have to update the .env configuration from Laravel Forge.
SCOUT_DRIVER=meilisearch
SCOUT_QUEUE=true
MEILISEARCH_HOST=http://127.0.0.1:7700
MEILISEARCH_KEY=YOUR_MEILISEARCH_KEY

Step 6: Import Laravel Scout Data


Once you have done that you need to SSH into your Laravel application server then run "scout:import" to import any of your models.
php artisan scout:import "App\Models\Post" 

Step 7: Test MeiliSearch


Assuming you follow the other tutorial Make Your Laravel Search Smartarter With Laravel Scout and MeiliSearch then you can test MeiliSearch from the URL by passing the query string for the search terms.
Route::get('/search-post', function () {
    $query = request()->query('query');

    $posts = Post::search($query)
        ->take(10)
        ->within('posts')
        ->get();

    return $posts;
});
MeiliSearch Result Preview

By now you should be able to Deploy MeiliSearch on Laravel Forge and on the next tutorial, you'll be learning to build the front-end for the search result so stay tuned for that. If you found this tutorial do share it with your friends and happy coding. 🎉 

Other Related Post

Alternative Tags

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

)