Meilisearch Set Up

Setting up the plugin

In your local dev environment, install the Meilisearch Connect plugin

Setting up in DDEV

Install Meilisearch

We need to configure DDEV to create a Meilisearch container when we run it for the site. To do this, create the following file in .ddev/docker-compose.meilisearch.yaml

NOTE that the version of Meilisearch used in this docker compose snippet is likely outdated and the latest version supported by our plugin should be used instead.

version: '3.6'
services:
  meilisearch:
	container_name: ddev-${DDEV_SITENAME}-meilisearch
	image: getmeili/meilisearch:v1.11.1
	hostname: ${DDEV_SITENAME}-meilisearch
	expose:
	  - "7700"
	environment:
	  - VIRTUAL_HOST=$DDEV_HOSTNAME
	  - HTTP_EXPOSE=7700:7700
	  - MEILI_MASTER_KEY=meilisearchlocal
	  - MEILI_ENV=development
	volumes:
	  - type: "volume"
		source: meilisearch
		target: "/data.ms"
		volume:
		  nocopy: true
	  - type: "bind"
		source: "."
		target: "/mnt/ddev_config"
	  - ddev-global-cache:/mnt/ddev-global-cache
	labels:
	  com.ddev.site-name: ${DDEV_SITENAME}
	  com.ddev.approot: ${DDEV_APPROOT}
  web:
	links:
	  - meilisearch:meilisearch

volumes:
  meilisearch:

Once you have created that file, restart DDEV

ddev restart

Create environment variables

Create the following environment variables in your project

MEILI_HOST_URL="http://YOUR_DDEV_DOMAIN:7700"
MEILI_ADMIN_API_KEY="meilisearchlocal"
MEILI_SEARCH_API_KEY="meilisearchlocal"

You'll also need to create variables for your required indexes. These will be used within the Meilisearch Connect config file. For example;

MEILI_PAGES_INDEX="pages"
MEILI_OER_INDEX="oer"
MEILI_PEARL_INDEX="pearl"

Create the Index config

Refer to the Meilisearch Connect documentation

Run the sync command

Before you can access the CP utility or do anything with Meilisearch Connect, you will need to sync the Meilisearch settings. Run the following command

ddev craft meilisearch-connect/sync/settings

Setting up a Staging instance

Create a Forge App

For the Staging instance we want to create an empty app within Forge. This can be done on the same server that the Staging site is running on.

  • Log in to Forge.
  • Locate the staging server for the site you are working on.
  • Click "New Site"
  • Add the domain, for consistency with our other sites use search-staging.example.com (CloudFlare doesn't like nested subdomains)
  • Project type should be PHP/Laravel/Symfony
  • The Web Directory doesn't really matter
  • PHP Version should be 8.3+
  • There is no need to create a database or do anything else
  • Click Add Site to create the site
  • Create an SSL certificate for the site within Forge

There is no need to configure anything else on this server. We will do the rest via the command line

Install Meilisearch

Next you will need to SSH into that Forge App and install Meilisearch. You can refer to the following instructions (even though this isn't for Production) https://www.meilisearch.com/docs/guides/running_production

Follow steps 1-4. There is no need to do any more for the staging instance.

You'll need to use sudo to create the service. The sudo password for the server should be recorded in Bitwarden.

When Meilisearch starts it will generate a master key. It is important to make a note of this in Bitwarden for future reference. You will need it later.

Configure a domain for Meilisearch

We then configure a domain name to point at that app. You may need to do this within Cloudflare if that's being used for the site. Add an A record pointing at search-staging for the staging domain.

Set up environment variables

In your Craft .env file, create environment variables for the API keys. For the purposes here we can use the same key for both Admin and Search API Keys.

MEILI_ADMIN_API_KEY="MASTERKEY"
MEILI_SEARCH_API_KEY="MASTERKEY"

Update Forge nginx config

Update your site's Nginx config file,

image

Test the Meilisearch instance

You should now be able to visit the Meilisearch staging domain in your browser and see the GUI

Setting up a Production instance

As above but with additional steps for the installation of Meilisearch