How to install and configure elasticsearch on magento 2
Installing and configuring Elasticsearch on Magento 2 involves several steps. Here’s a step-by-step guide to help you with the process:
Step 1: Install Elasticsearch
First, you need to install Elasticsearch on your server. Here’s how you can do it:
- Add the Elasticsearch repository to your system:
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch sudo vi /etc/yum.repos.d/elasticsearch.repo
- Add the following configuration to the file and save it:
[elasticsearch-7.x] name=Elasticsearch repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md
- Install Elasticsearch using yum:
sudo yum install elasticsearch
Step 2: Configure Elasticsearch
Once Elasticsearch is installed, you need to configure it by editing the configuration file. Here’s how you can do it:
- Open the Elasticsearch configuration file:
sudo vi /etc/elasticsearch/elasticsearch.yml
- Add the following configuration to the file:
cluster.name: magento node.name: magento network.host: localhost http.port: 9200
- Save and exit the file.
- Restart Elasticsearch:
sudo systemctl restart elasticsearch
Step 3: Install the Elasticsearch module for Magento
Now that Elasticsearch is installed and configured, you need to install the Elasticsearch module for Magento. Here’s how you can do it:
- Log in to your Magento 2 server.
- Change to your Magento root directory:
cd /var/www/html/magento2
- Install the Elasticsearch module using composer:
composer require magento/module-elasticsearch
- Run the Magento setup upgrade command:
bin/magento setup:upgrade
Step 4: Configure Magento to use Elasticsearch
Finally, you need to configure Magento to use Elasticsearch as its search engine. Here’s how you can do it:
- Log in to your Magento 2 Admin Panel.
- Go to Stores > Configuration > Catalog > Catalog > Catalog Search.
- Set the following options:
- Search Engine: Elasticsearch 7.0+
- Elasticsearch Server Hostname: localhost
- Elasticsearch Server Port: 9200
- Save the configuration and flush the Magento cache:
bin/magento cache:flush
That’s it! Elasticsearch is now installed and configured on your Magento 2 server, and Magento is set up to use it as its search engine.