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
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
# extract the service installation file
tar xzf solr-6.6.0.tgz solr-6.6.0/bin/ --strip-components=2
# install Solr as a service
sudo ./ solr-6.6.0.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., 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

Enable the Search API Solr module + the Solr Search Defaults module, that comes with an example default content index configuration.

# cd in your docroot then
drush en search_api_solr search_api_solr_defaults
# or better, if using Composer template for Drupal, having Drush that is not installed globally
# ../vendor/bin/drush en search_api_solr search_api_solr_defaults

Go to the Search API configuration (/admin/config/search/search-api), add your Solr server, setting 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_index/edit), activate the index then index your content.


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.