In this post, you'll be learning how to host MeiliSearch on the production ubuntu server and integrate it with your Laravel project. You can make use of any VPS platform such as Vultr or Hetzner or DigitalOcean and for this case, we'll be showing you how to set up the one that's ready-created by Laravel Forge.
The first step is to SSH into the server and installs MeiliSearch with curl. Do note that you need to install this within the user directory which is "forge".
Step 1: SSH into the server and Install MeiliSearch
The first step is to SSH into the server and installs MeiliSearch with curl. Do note that you need to install this within the user directory which is "forge".
/home/forge
Once you are in the user directory you can install MeiliSearch using curl and move the binaries to the "/usr/bin" directory.
# Install MeiliSearch curl -L https://install.meilisearch.com | sh # Move MeiliSearch bindary to the system binaries mv ./meilisearch /usr/bin
By moving the binary into the system binaries now you will be able to run the "meilisearch" command from anywhere.
The next step is to run MeiliSearch as a service that will always be running in the background. By making it a service, it will automatically be launched when the system reboot and etc.
To add the service, create a new "meilisearch.service" using vim as follows.
Step 2: Run MeiliSearch as a Service
The next step is to run MeiliSearch as a service that will always be running in the background. By making it a service, it will automatically be launched when the system reboot and etc.
To add the service, create a new "meilisearch.service" using vim as follows.
sudo vim /etc/systemd/system/meilisearch.service
Paste the following script, do note that you will have to change your "YoUrV3ry-S3cur3-aP1k3Y" master key into your own secure defined master key.
[Unit] Description=MeiliSearch After=systemd-user-sessions.service [Service] Type=simple ExecStart=/usr/bin/meilisearch --http-addr 127.0.0.1:7700 --env production --master-key YoUrV3ry-S3cur3-aP1k3Y [Install] WantedBy=default.target
Once you have pasted it now you can save it by typing :wq which is "write and quit" command in vim.
:wq
Step 3: Enable and Start the Service
Once it's ready now you can enable and start the service by running the command below. Do note that you might need to input your sudo password.
# Enable meilisearch service systemctl enable meilisearch # Start the meilisearch service systemctl start meilisearch # Check that the service is actually running systemctl status meilisearch
When checking if MeiliSearch is running you will get output as follows.
● meilisearch.service - MeiliSearch Loaded: loaded (/etc/systemd/system/meilisearch.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2021-08-11 07:49:49 +08; 10s ago Main PID: 3486507 (meilisearch)
Step 4: Connect With Laravel
Now that you have MeiliSearch running in the background, you can update the Laravel environment (.env) file to specify MeiliSearch as the SCOUT driver.
SCOUT_DRIVER=meilisearch SCOUT_QUEUE=true MEILISEARCH_HOST=http://127.0.0.1:7700 MEILISEARCH_KEY=YOUR_MEILISEARCH_KEY
Other Tutorial
- How to Deploy MeiliSearch on Laravel Forge
- Make Your Laravel Search Smartarter With Laravel Scout and MeiliSearch
By now you should be able to Set up Meilisearch on Production Ubuntu for the Laravel project. If you found this tutorial to be helpful do share it with your friends and cheers.
Leave a reply