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:
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="

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

Sometimes you need to style certain elements differently when working across various language translations. This easy tutorial can help you…
Getting TypeError: $(...).once is not a function in your Drupal 8 site? Easily fixed.


When using Swiftmailer under Drupal 8 / 9 it automatically sets the headers for sender to…
Yes, IOS / Safari is the new internet explorer. Amount of time I spend on debugging…
There is a very handy function in Drupal 8 / 9, allowing developers refresh view when…
Often, when doing SEO checkups, SEO specialist come up with adding Schema.org…
I needed to test my contracts against USDC contract, specifically I needed ERC-721 mint…