Skip to main content
Server & DevOpsOctober 3, 202412 min read

How to Set Up OpenSearch for Magento 2.4.7 on Ubuntu 22.04/24.04

Step-by-step instructions for installing and configuring OpenSearch for Magento 2.4.7 on Ubuntu, including single-node setup, optional cluster configuration, security certificates, and Magento integration.

Setting Up OpenSearch for Magento 2.4.7 on Ubuntu

Magento 2.4.7 requires OpenSearch (or Elasticsearch) for its catalog search. Getting it right matters -- a misconfigured search engine means broken product search, failed reindexing, and frustrated customers. This post covers a straightforward install on Ubuntu 22.04/24.04, plus an optional cluster setup if you need redundancy.

Prerequisites

  • System Requirements:
    • Ubuntu 22.04 LTS or Ubuntu 24.04 LTS installed.
    • Root or sudo user privileges.
    • Minimum hardware requirements for Magento and OpenSearch.
  • Installed Software:
    • Java 11 or higher (required for OpenSearch).
    • LAMP/LEMP stack (Linux, Apache/Nginx, MySQL/MariaDB, PHP) for Magento.
    • Composer (for Magento installation).

Step 1: Update System Packages

sudo apt update
sudo apt upgrade -y

Step 2: Install Java

sudo apt install openjdk-11-jdk -y
java -version

Step 3: Install OpenSearch

Add the official OpenSearch repository and install:

sudo apt update
sudo apt install opensearch -y

Using the official repo means you'll get a version that's compatible with Magento 2.4.7 out of the box.

Step 4: Configure OpenSearch

Single-Node Configuration

Open the config file:

sudo nano /etc/opensearch/opensearch.yml

Set these values:

cluster.name: magento-cluster
node.name: node-1
network.host: 127.0.0.1
plugins.security.disabled: true  # Disable security for development only

This tells OpenSearch to listen only on localhost, which is what Magento expects when both run on the same box. Note: Don't disable security in production -- this is a dev/staging shortcut only.

Optional: Configuring an OpenSearch Cluster

If you need high availability, you can spread OpenSearch across multiple nodes.

Step 4.1: Prepare Multiple Nodes

You'll need:

  • At least two or more servers with Ubuntu 22.04/24.04.
  • Each node should have OpenSearch installed following the steps above.

Step 4.2: Configure Each Node

Edit /etc/opensearch/opensearch.yml on each node:

cluster.name: magento-cluster
node.name: node-1  # Change for each node (node-2, node-3, etc.)
network.host: 0.0.0.0
discovery.seed_hosts: ["node1-ip", "node2-ip", "node3-ip"]
cluster.initial_master_nodes: ["node-1", "node-2"]

A few things to note here:

  • cluster.name must be identical on every node -- mismatch and they won't find each other
  • node.name needs to be unique per node
  • discovery.seed_hosts is how nodes discover each other during cluster formation
  • cluster.initial_master_nodes bootstraps the cluster on first start

Step 4.3: Configure Firewall and Network Settings

Open the necessary ports on all nodes:

sudo ufw allow 9200/tcp
sudo ufw allow 9300/tcp

Port 9200 handles REST API calls. Port 9300 is for inter-node communication.

Step 4.4: Generate Security Certificates

Navigate to the OpenSearch directory:

cd /usr/share/opensearch/

Generate certificates using the OpenSearch security plugin:

sudo plugins/opensearch-security/tools/securityadmin.sh -cd plugins/opensearch-security/securityconfig/ -ca -cert

Copy the certificates to all nodes and make sure permissions are correct. This is one of those steps that's easy to rush and regret later.

Step 5: Start and Enable OpenSearch

sudo systemctl enable opensearch
sudo systemctl start opensearch

Verify it's actually running:

sudo systemctl status opensearch

Step 6: Install Magento 2.4.7

(Skip this if Magento is already installed.)

Install Composer:

sudo apt install composer -y

Set up the web server and PHP extensions:

  • Install Apache/Nginx, PHP 8.x, and required PHP extensions.

Create the Magento project:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.7

Set file permissions and ownership, then create a MySQL/MariaDB database and user for Magento.

Run the Magento installation script:

bin/magento setup:install --base-url=http://your-domain.com/ \
--db-host=localhost --db-name=magento --db-user=magento_user --db-password=your_password \
--admin-firstname=Admin --admin-lastname=User --admin-email=admin@example.com \
--admin-user=admin --admin-password=Admin123 --language=en_US \
--currency=USD --timezone=America/Chicago --use-rewrites=1 \
--search-engine=opensearch --opensearch-host=127.0.0.1 --opensearch-port=9200

Step 7: Configure Magento to Use OpenSearch

Already have Magento installed? Just point it at OpenSearch:

bin/magento config:set catalog/search/engine opensearch
bin/magento config:set catalog/search/opensearch_server_hostname 127.0.0.1
bin/magento config:set catalog/search/opensearch_server_port 9200
bin/magento indexer:reindex catalogsearch_fulltext
bin/magento cache:flush

Step 8: Verify the Setup

Check cluster health:

curl -XGET 'http://127.0.0.1:9200/_cluster/health?pretty'

List cluster nodes:

curl -XGET 'http://127.0.0.1:9200/_cat/nodes?v'

Test Magento store search functionality:

  • Do a few searches on the storefront and make sure results come back correctly.

Keep an eye on logs for anything unexpected:

sudo tail -f /var/log/opensearch/opensearch.log

That's it -- OpenSearch is running and Magento is using it for catalog search. If you went with the cluster setup, you've also got redundancy in case a node goes down. One thing I'd stress: keep OpenSearch updated, and don't run with security disabled in production. It's tempting to skip the certificate setup, but it's not worth the risk.

Need help with this?

Our team handles this kind of work daily. Let us take care of your infrastructure.