Install Solr 6 for Drupal 8 on Ubuntu 16.04

Submitted by christophe on Wed, 26/10/2016 - 21:55
Solr logo

 

This setup is intended for production use on a dedicated server (VPS, ...).
For development purpose it should be preferable to use Drupal VM, it comes with a default Solr configuration that can be enabled via the config.yml file. If you are using Drupal VM and want to configure Search API for Solr, you can jump to point 4.

1. Install Search API and Search API Solr modules

Make sure that you download the modules via Composer and not Drush, otherwise you will end up with missing dependencies (like Solarium).

# cd in your Drupal docroot first
composer config repositories.drupal composer https://packagist.drupal-composer.org/8
composer require drupal/search_api_solr

2. Install Solr

Update your system

sudo apt-get update && apt-get upgrade -y

Install Java 8

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

# check if Java is installed properly, should return java version "1.8.x_yy"
java -version

Install Solr

cd /root
# get the latest 6.x release via https://lucene.apache.org/solr/mirrors-solr-latest-redir.html
wget http://www-eu.apache.org/dist/lucene/solr/6.2.1
# extract the service installation file
tar xzf solr-6.2.1.tgz solr-6.2.1/bin/install_solr_service.sh --strip-components=2
# install Solr as a service
sudo ./install_solr_service.sh solr-6.2.1.tgz

# check the service status
service solr status

Create a collection (also known as "core")

sudo su - solr -c "/opt/solr/bin/solr create -c my_collection -n data_driven_schema_configs"

The Solr interface that allows to browse collections, should be accessible via the :8983 port (e.g. http://xxx.xxx.xxx.xxx:8983/solr/), make sure that the access is restricted (e.g. by a firewall for your IP only or a basic authentication mechanism).

3. Restrict access to the Apache Solr admin interface

Various methods can be used to restrict access, the most generic one is to use iptables, it will limit access to the port to specifig IP's (e.g. if not using a VPN), including localhost.

sudo iptables -A INPUT -p tcp -s localhost --dport 8983 -j ACCEPT
sudo iptables -A INPUT -p tcp -s YOUR_STATIC_IP --dport 8983 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 8983 -j DROP

This will define IP rules until the next reboot.
To make them peristent, use the generic iptables-save or netfilter-persistent (on Ubuntu 16.04)

sudo netfilter-persistent save
sudo netfilter-persistent reload

4. Configure Search API

Set the valid schema for the collection

# if not done yet (if you skipped the first sections), create your collection
sudo su - solr -c "/opt/solr/bin/solr create -c my_collection -n data_driven_schema_configs"
# replace my_collection by your own collection name
cd /var/solr/data/my_collection
# backup the configuration directory
mv conf conf.orig
# copy the Search API configuration, if using DrupalVM prefer 5.x at the time of writing 
cp -R /path/to/contrib_modules/search_api_solr/solr-conf/6.x conf
# change owner and group
chown -R solr:solr conf
# change permissions
chmod -R 775 conf
# restart Solr service
service solr restart

Head to Search API configuration (/admin/config/search/search-api/server/default_solr_server/edit) then set the name of your collection under the Solr core field. Other values can be left as is in this basic configuration.
You can then continue by setting up the default index under /admin/config/search/search-api/index/default_solr_index/edit.

Ressources

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.