Tutorial

Configuring Search API using Apache Solr for Drupal 7 under Ubuntu 20.04

I had trouble to set this up properly, because documentation is quite misleading or often not there at all. Basicly nowdays (2022) it is all about Drupal 8 / 9. But what if you have an older website and need a speed boost in Search API views?

You came to a right place.

Pridal/a lubo dňa Po, 08/22/2022 - 20:37
Install Apache Solr version 7.7.0 under Ubuntu 20.04

It is crucial for you to install Apache Solr 7.7.0! Not higher version (currently Solr 8.9), because Drupal 7 will not work with higher version at all!

1.1. Install Java

Install Java.

$ sudo apt install default-jdk -y

Verify the Java installation.

$ java -version

1.2. Install Apache Solr

To download the latest version of Apache Solr, go to the Apache official download website.

Download Apache Solr.

$ sudo wget https://archive.apache.org/dist/lucene/solr/7.7.0/solr-7.7.0.tgz

Extract the downloaded archives.

$ sudo tar xzf solr-7.7.0.tgz

Install Apache Solr.

$ sudo bash solr-7.7.0/bin/install_solr_service.sh solr-7.7.0.tgz

Check the status of the Apache Solr service.

$ sudo systemctl status solr

Enable the Apache Solr service to start on system boot.

$ sudo systemctl enable solr

Allow port 8983 through the UFW firewall.

$ sudo ufw allow 8983

To access the Apache Solr web interface, go to your browser and enter http://serverIP:8983. For example:

http://192.0.2.11:8983
Create Apache Solr Core

Do not use build-in GUI of Apache Solr on port 8983. While I believe it might work, for me it did not and yielded a few errrors. It is easier to do it in terminal.

The core needs to be created under the user "solr". Use the following command:

sudo -u solr ./bin/solr create -c mycore
Copy the XML configuration from Drupal to the newly created Core

This step was crucial and I only happened to stumble upon solution in this issue thread:

3.1. Copy all configuration files from the module folder (search_api_solr/solr-conf/7.x) to {solr_installation_folder}/server/solr/{core_name}/conf folder

- For me I needed to copy from "/var/www/clients/client1/web67/web/sites/all/modules/search_api_solr/solr-conf/7.x" to "/var/solr/data/mycore/conf"

3.2. Restart solr server using command:

Sudo service solr restart

 

Add Solr Server to Search API configuration inside Drupal

Steps from there are pretty much easy. 

4.1. Go to /admin/config/search/search_api in your website and hit "Add server".

4.2. Select Solr service under Service Class selection box

4.3. Creditials:
HTTP protocol leave at "http"
Solr host have to be IP address of your server (or localhost, if you are developing locally)
- Solr port is default 8983
- Solr path is /solr/mycore

Secure your Apache Solr Installation

While generally speaking version 7.7.0 is not secure enough and you will need to do some patching yourself because of security holes, you can at least get rid of Apache Solr GUI on URL http://your_server_ip:8983/solr/

5.1. Open the file /etc/default/solr.in.sh

5.2. Add the following line at the very end of the file:

SOLR_OPTS="$SOLR_OPTS -Djetty.host=127.0.0.1"

5.3. Restart Apache Solr using the command:

Sudo service solr restart

This will prevent people from visiting your admin GUI for apache Solr. You can always SSH tunnel yourself in so you can visit this URL safely, or you can simply remove the line and reload Solr temporarily.

Might interest you

Tutorial
I don't understand why some of the decisions were made in Drupal, nor in Drupal Commerce, but this one strikes me hard. For some reason,…
Tutorial
In this case we have two options, either we use hook_user_presave() or we can create new submit handler and use that. 

Recommended

Article
32 views
For the past few days I am trying to comprehend why / how this blockchain even gained it'…
Tutorial
95 views
This sketch is quite easy, I used Arduino Nano with OLED 0.96″ display 128×64 resolution…
Tutorial
157 views
While working on a fairly complex website with very complex views setup, including tens…
Tutorial
14 views
In this case we have two options, either we use hook_user_presave() or we can create new…
Tutorial
15 views
When using Swiftmailer under Drupal 8 / 9 it automatically sets the headers for sender to…
Tutorial
7 views
Yes, IOS / Safari is the new internet explorer. Amount of time I spend on debugging…
Tutorial
43 views
There is a very handy function in Drupal 8 / 9, allowing developers refresh view when…
Tutorial
22 views
Often, when doing SEO checkups, SEO specialist come up with adding Schema.org…
Tutorial
174 views
I needed to test my contracts against USDC contract, specifically I needed ERC-721 mint…
Tutorial
85 views
If you are a newbie like I am and struggling with setting the proper MYSQL my.cnf config…
Tutorial
25 views
I had trouble to set this up properly, because documentation is quite misleading or often…
Article
72 views
As the title says, DO NOT in any circumstances install ANY bitcoin price extension to ANY…
Tutorial
278 views
This is (or should be) a working example of sending some Ether between two addresses.…
Module
45 views
This list was fetched from Zapper, with their /v1/token-list endpoint. Which you can…
Tutorial
143 views
In the last months I am being pretty much bombarded by my clients with asking what…