Every application eventually needs search. At first, a few WHERE LIKE queries get the job done. But as your data grows and your users expect instant, typo-tolerant, relevant results, those SQL queries start showing their age. Response times climb, relevancy suffers, and your users notice.
Meilisearch is an open-source, lightning-fast search engine that was practically designed for this moment. It returns results in milliseconds, handles typos gracefully, and integrates seamlessly with Laravel through the Scout package. And with Deploynix, provisioning a dedicated Meilisearch server takes minutes.
In this guide, we will walk through the complete setup: provisioning a Meilisearch server on Deploynix, connecting it to your Laravel application via Scout, indexing your data, and tuning search relevancy for the best possible user experience.
Why Meilisearch?
Before we dive into the setup, let us understand what makes Meilisearch the right choice for most Laravel applications.
Speed. Meilisearch is designed to return results in under 50 milliseconds, regardless of dataset size. For most datasets, you will see results in under 20 milliseconds. This speed is not just a nice-to-have — it enables real-time search-as-you-type interfaces that feel instantaneous.
Typo tolerance. Users make typos. Meilisearch handles them gracefully out of the box. A search for "deploymnet" will still find "deployment" without any additional configuration. This dramatically improves search usability.
Relevancy. Meilisearch uses a sophisticated ranking system that considers word proximity, attribute importance, exactness, and custom ranking rules. Results feel intuitive without manual tuning, though you can customize the ranking when needed.
Simplicity. Unlike Elasticsearch, which requires understanding complex query DSLs and managing JVM memory, Meilisearch is a single binary with a straightforward HTTP API. Configuration is minimal, and the defaults work well for most use cases.
Laravel integration. Through Laravel Scout, Meilisearch feels like a native part of your application. You add a trait to your model, define what is searchable, and Scout handles the rest — indexing, updating, and removing documents automatically as your Eloquent models change.
Step 1: Provision a Meilisearch Server
In your Deploynix dashboard, click "Create Server" and select the Meilisearch server type.
Sizing Your Server
Meilisearch is CPU-intensive during indexing and memory-intensive during search. For sizing:
- Small datasets (under 100,000 documents): 1GB RAM / 1 vCPU is sufficient
- Medium datasets (100,000 to 1 million documents): 2-4GB RAM / 2 vCPU
- Large datasets (over 1 million documents): 4-8GB RAM / 4 vCPU
Meilisearch loads its entire index into memory for fastest search performance, so RAM is the most important resource to get right. A rough guideline is that your server should have at least 1.5x the size of your raw data in available RAM.
Region Selection
Choose the same region as your application server. Network latency between your app and Meilisearch should be as low as possible since search requests happen synchronously during user interactions.
Provisioning
Click "Create Server" and Deploynix will provision the VM, install Meilisearch, configure it with secure defaults, and set up a master key for API authentication. The master key is displayed in your server dashboard — you will need it to connect your Laravel application.
Deploynix configures Meilisearch with:
- A secure master key for API authentication
- Firewall rules that only allow connections from your application servers
- Systemd to manage the Meilisearch process and auto-restart on failure
- Optimized settings for production use
Step 2: Network Access via HTTPS Reverse Proxy
Deploynix configures Meilisearch to listen only on localhost (127.0.0.1:7700) and sets up an Nginx reverse proxy with SSL termination. Your application connects to Meilisearch over HTTPS using the vanity subdomain assigned to your server (for example, ms-happy-swift-tiger.deploynix.cloud).
This means you do not need to open port 7700 in your network rules. All traffic flows over HTTPS (port 443), which is already allowed by default. If you need to restrict access further, navigate to your Meilisearch server's Network Rules in the Deploynix dashboard and add rules to limit inbound HTTPS connections to your application server's IP address.
Step 3: Install Laravel Scout and the Meilisearch Driver
In your Laravel application, install Scout and the Meilisearch PHP SDK:
composer require laravel/scout meilisearch/meilisearch-php
Publish the Scout configuration file:
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
This creates config/scout.php where you can configure your search driver.
Step 4: Configure Environment Variables
Add the following to your .env file on Deploynix (through the environment editor in your site dashboard):
SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=https://your-vanity-subdomain.deploynix.cloud
MEILISEARCH_KEY=your-master-key-from-deploynix-dashboard
Replace the host with your Meilisearch server's vanity subdomain (shown in the server dashboard) and the key with the master key Deploynix generated during provisioning.
Step 5: Make Your Models Searchable
Add the Searchable trait to any Eloquent model you want to include in search:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
class Article extends Model
{
use Searchable;
/**
* Get the indexable data array for the model.
*
* @return array<string, mixed>
*/
public function toSearchableArray(): array
{
return [
'id' => $this->id,
'title' => $this->title,
'body' => $this->body,
'author_name' => $this->author->name,
'category' => $this->category->name,
'published_at' => $this->published_at?->timestamp,
'views' => $this->views,
];
}
}
The toSearchableArray method defines what data Meilisearch indexes. Be intentional about what you include:
- Include fields users will search by. Title, body, author name, category — anything a user might type in a search box.
- Include fields you want to filter or sort by. Published date, view count, category — these enable faceted search and sorted results.
- Exclude sensitive data. Do not index passwords, API keys, or private user information.
-
Flatten relationships. Meilisearch works with flat documents, not nested objects. Include
$this->author->namerather than the entire author relationship.
Step 6: Import Existing Data
If you have existing data in your database, you need to import it into Meilisearch:
php artisan scout:import "App\Models\Article"
This command reads all records from your database and sends them to Meilisearch in batches. For large datasets, this can take a while. Scout processes records in chunks to avoid memory issues.
You can monitor import progress in your Meilisearch dashboard or by checking the task queue through the Meilisearch API.
Keeping Data in Sync
Once the initial import is complete, Scout automatically keeps Meilisearch in sync with your database. When you create, update, or delete an Eloquent model, Scout sends the change to Meilisearch.
For bulk operations that bypass Eloquent events (like raw queries or DB::table() updates), you need to manually trigger a re-import or use Scout's searchable() method on a collection.
Step 7: Implement Search in Your Application
With everything configured, searching is beautifully simple:
$articles = Article::search('deploying laravel applications')->get();
This returns an Eloquent collection of Article models that match the search query, complete with all relationships and accessors. Meilisearch handles the full-text search, typo tolerance, and relevancy ranking. Scout hydrates the results back into Eloquent models.
Filtering Results
You can combine search with filters:
$articles = Article::search('deployment')
->where('category', 'tutorials')
->get();
Paginating Results
Scout integrates with Laravel's pagination:
$articles = Article::search('deployment')->paginate(15);
Ordering Results
By default, Meilisearch orders results by relevancy. You can customize the sort order:
$articles = Article::search('deployment')
->orderBy('published_at', 'desc')
->get();
Tuning Search Relevancy
Meilisearch's default relevancy works well out of the box, but you can fine-tune it for better results.
Searchable Attributes Priority
By default, Meilisearch searches all indexed attributes with equal weight. You can prioritize certain attributes:
// In a setup command or migration
$client = app(\Meilisearch\Client::class);
$client->index('articles')->updateSearchableAttributes([
'title', // Highest priority
'body', // Second priority
'author_name', // Third priority
'category', // Lowest priority
]);
A match in the title field will now rank higher than the same match in the body field, which matches user expectations — if someone searches for "deployment," an article titled "Deployment Best Practices" should rank above an article that merely mentions deployment in paragraph seven.
Filterable Attributes
To use where clauses in your Scout queries, you must tell Meilisearch which attributes are filterable:
$client->index('articles')->updateFilterableAttributes([
'category',
'author_name',
'published_at',
]);
Sortable Attributes
Similarly, to use custom sort orders, declare sortable attributes:
$client->index('articles')->updateSortableAttributes([
'published_at',
'views',
]);
Custom Ranking Rules
Meilisearch applies ranking rules in order. The default order is: words, typo, proximity, attribute, sort, exactness. You can customize this:
$client->index('articles')->updateRankingRules([
'words',
'typo',
'proximity',
'attribute',
'sort',
'exactness',
'views:desc', // Popular articles rank higher
]);
Adding views:desc as a tiebreaker means that when two articles are equally relevant to a search query, the one with more views ranks first.
Stop Words
Configure common words that should be ignored during search to improve relevancy:
$client->index('articles')->updateStopWords([
'the', 'a', 'an', 'is', 'are', 'was', 'were',
'in', 'on', 'at', 'to', 'for', 'of', 'with',
]);
Synonyms
Define synonyms so users find results regardless of which term they use:
$client->index('articles')->updateSynonyms([
'deploy' => ['ship', 'release', 'publish'],
'server' => ['vps', 'instance', 'machine', 'droplet'],
'database' => ['db', 'mysql', 'postgres'],
]);
Indexing Best Practices
Queue Index Updates
For production applications, configure Scout to queue index updates:
SCOUT_QUEUE=true
This prevents search indexing from slowing down your web requests. When a model is saved, the index update is dispatched to your queue and processed asynchronously by your workers.
Batch Imports for Large Datasets
For very large datasets (millions of records), the default scout:import command might be slow. You can increase the chunk size:
php artisan scout:import "App\Models\Article" --chunk=1000
Index Settings Before Import
Always configure your index settings (searchable attributes, filterable attributes, ranking rules) before importing data. Changing these settings after import triggers a re-index, which can take time for large datasets.
Monitoring Meilisearch
Deploynix provides server-level monitoring for your Meilisearch server, including CPU usage, memory consumption, and disk I/O. High memory usage is expected — Meilisearch loads indexes into memory for performance.
Watch for these warning signs:
- Memory usage approaching server limits: Time to upgrade your server or optimize your index (remove unnecessary attributes).
- High CPU during non-import periods: Could indicate an inefficient search pattern or too many concurrent search requests.
- Disk usage growing rapidly: Check if old tasks are accumulating. Meilisearch stores task history that can be pruned.
Conclusion
Meilisearch and Laravel Scout together deliver a search experience that feels native to your application while performing at a level that SQL queries simply cannot match. With Deploynix, the infrastructure side of the equation is solved in minutes: a dedicated Meilisearch server, properly configured and monitored, ready to index your data and serve results in milliseconds.
Start with the defaults, import your data, and ship a search feature that your users will love. Tune relevancy and ranking rules as you learn what your users search for and what results they expect.
Provision your Meilisearch server at deploynix.io and give your users the search experience they deserve.
Top comments (0)