VPS

Installing Elasticsearch for your Hosting or VPS

What is Elasticsearch?

Elasticsearch logo

Elasticsearch is a search engine known for its high performance. It integrates with many environments and is especially popular on websites, for example online stores built with PrestaShop or Magento.

It installs at the operating-system level, depends on Java and requires execution permissions on the /tmp directory. This makes a secure integration in a shared hosting environment very complex.

Bottom line: Elasticsearch needs a VPS server. But do not worry - it is very easy to install and costs less than €10/month. Also, you do not need to move your website: an additional VPS running the search engine is enough.

Installing Elasticsearch on a Debian VPS

Your VPS needs at least 2 GB of RAM. You will need more resources depending on how much data you index and the search workload it has to process.

Once you have your VPS, install it with Debian (the default operating system). You will receive an e-mail with the connection details: the VPS's dedicated IP and the root password.

Connect to your server over SSH and run the following commands:

apt update; apt dist-upgrade -y; apt install gnupg curl nano wget sudo apt-transport-https -y;
timedatectl set-timezone Europe/Madrid
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -; apt update;

To install Elasticsearch v7, run:

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-7.x.list; apt install elasticsearch -y;

To install Elasticsearch v8 instead, run:

echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee /etc/apt/sources.list.d/elastic-8.x.list; apt install elasticsearch -y;

Then edit the /etc/elasticsearch/elasticsearch.yml file and set the xpack.security.enabled variable to false:

nano /etc/elasticsearch/elasticsearch.yml
xpack.security.enabled: false

Finally, start the service and enable it so it starts automatically when the VPS reboots:

systemctl restart elasticsearch
systemctl enable elasticsearch

Check that the service is up:

systemctl status elasticsearch

And that it responds to requests:

curl -X GET localhost:9200

Done - Elasticsearch is installed!

Securing the Elasticsearch server

To prevent anyone from connecting to your Elasticsearch, protect it with firewall rules. Install UFW and set the default policy:

apt install ufw -y
ufw default deny incoming
ufw default allow outgoing
ufw allow 22
ufw allow 80
ufw allow 443
ufw enable

Allow connections to port 9200 only from your hosting's IP (replace x.x.x.x with the IP of the hosting where your website lives):

ufw allow from x.x.x.x to any port 9200

Enable the firewall and review the rules:

ufw enable
ufw status numbered

Any questions? Contact our technical support - we will be happy to help.