Meilisearch and other search services
Typo-tolerant, instant search is one of the first things users miss when a site grows past a few hundred records. SrvYard installs Meilisearch, an open-source search engine, as a managed service: a pinned release, a systemd unit, a generated master key and a safe network setting, all from the Services tab or from the server creation form.
Meilisearch is the only search engine SrvYard installs today. There is no Elasticsearch, OpenSearch or Typesense entry in the list, and this article does not pretend otherwise. Those can be installed by hand over SSH, but SrvYard will not manage them.
Before you begin
- A server in the Ready state and the permission to manage services.
- Enough memory. A search index lives mostly in memory and on disk. A small server is fine for thousands of documents; plan more for millions.
- Decide where it runs. The simplest setup is one search server for the whole organisation, reached over the private network. The cheapest is Meilisearch on the same server as the application. Either way, read step 4 before you put real data in it.
1. Create a dedicated search server
When you add a server, Server type decides what SrvYard installs.
- Meilisearch server. Select this card on Servers > Add server. The card says A search server that includes Meilisearch and Installs Meilisearch. The rest of the form (name, provider, region and size) is the same as for any server. A short note in the advanced options says that a master key is generated and kept encrypted, and that the search engine listens on localhost, or on the private IP when the server has one.
You will see the server provision, and a Meilisearch row appears on its Services tab when it is done.
2. Add Meilisearch to a server you already have
Open the server's Services tab and press Install service.
- Meilisearch. The card reads A fast, typo-tolerant search engine. Protected by a master key and bound to localhost or the private IP. It is listed with the type Search.
- Install Meilisearch. Starts the installation. SrvYard downloads the pinned release of the official binary (and falls back to the official installer when that file cannot be fetched), creates a
meilisearchsystem user, and starts the service. The output is shown live.
Under the hood the files live in fixed places that are handy to know: the program in /usr/local/bin/meilisearch, the data in /var/lib/meilisearch, the dumps in /var/lib/meilisearch/dumps and the settings in /etc/meilisearch.env, which only root can read. The service runs in production mode with analytics switched off.
3. Check that it runs
- The Meilisearch row shows the type Search, the installed version, the status and whether it starts at boot. Open the menu at the end of the row for Start, Stop, Restart, Start at boot or Do not start at boot, and View logs. There is no Edit configuration entry: the few settings Meilisearch needs are written by SrvYard, and the master key is not meant to be edited by hand.
Uninstalling Meilisearch deletes its data and forgets the master key, so type the service name carefully when SrvYard asks. A later installation generates a new key, and every client has to be updated.
4. Reach it from your application
Meilisearch listens on port 7700. Where it listens depends on the server:
- No private IP set: it binds to
127.0.0.1. Only programs on the same server can use it, which is right when the application runs there too. - A private IP set on the server (see Settings > Server network): it binds to that private address, so servers on the same private network can reach it once the firewall allows them.
SrvYard does not open the port on its own. For a separate search server, add a firewall rule that allows port 7700 over TCP from the private address (or range) of your application servers only.
- The rule. Here Meilisearch from the private network allows TCP port 7700 from
10.0.0.0/16. SSH, HTTP and HTTPS are the default rules. Create the same kind of rule with Add rule, as described in Remote access, phpMyAdmin and SSH tunnels.
Do not open 7700 to the world. Even with a master key, a public search port invites scanning and attacks. If you need to inspect the index from your laptop, use an SSH tunnel to port 7700.
5. Use the master key
The master key is generated when Meilisearch is installed and stored encrypted in SrvYard. It is the password for the whole instance, so use it only on the server side of your application, never in browser code. SrvYard does not show it in the interface. The key is also in /etc/meilisearch.env as MEILI_MASTER_KEY, which an administrator can read over SSH with sudo cat /etc/meilisearch.env.
With the key, create narrower API keys through Meilisearch itself, a search-only key for the front end and an admin key for indexing. Then give your Laravel site the settings it needs on its Environment tab:
SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=http://10.0.1.70:7700
MEILISEARCH_KEY=the-key-for-the-application
Use http://127.0.0.1:7700 when the engine is on the same server. The application also needs Laravel Scout and the Meilisearch PHP client, added with composer require laravel/scout meilisearch/meilisearch-php http-interop/http-factory-guzzle. After saving, deploy and index your models with php artisan scout:import "App\Models\Post".
6. Back up and rebuild
A search index is a copy of data that lives in your database, so the best backup is the database itself: back it up and re-run scout:import if the index is ever lost. SrvYard's database backups cover the databases of MySQL, MariaDB and PostgreSQL, not the Meilisearch data directory. If rebuilding a very large index would take hours, ask Meilisearch to create a dump (it is written to /var/lib/meilisearch/dumps), or take a provider snapshot of the whole search server before risky changes.
Keep one index per environment and name them clearly, for example production_posts, so that a staging site pointed at the same server cannot overwrite live data by accident.
Troubleshooting
- The installation fails while downloading. The server cannot reach GitHub or the installer address. Check outbound access and retry Install Meilisearch; the output shows the failing step.
- "Connection refused" from the application. The service is stopped, or the host and port are wrong. On another server, the engine only listens on the private IP: use that address, not the public one.
- The application times out reaching the search server. The firewall has no rule for the application's address, or the two servers are not on the same private network.
- "The provided API key is invalid". The key in the
.envis not the master key or one derived from it. Meilisearch keys are case sensitive; copy the whole value. - The index is gone after I uninstalled the service. Uninstalling removes the data. Reindex from your database with
scout:import, and keep the source of truth in your database. - I cannot see the master key in SrvYard. It is not shown in the interface. Read it over SSH from
/etc/meilisearch.envas an administrator.
Related
- Redis, Memcached and cache services: another service installed the same way.
- Remote access, phpMyAdmin and SSH tunnels: firewall rules and tunnels.
- Create a database and a user: the data you will index.
- Create a site on your server: where the application that searches lives.