How to install Apache Solr 5.x for use with Drupal

Here's the updated version on how-to install Apache Solr 5.x and get it running with Drupal (WITHOUT Apache Tomcat; as Solr 5.x doesn't support Tomcat anymore).

Install Java 1.8

yum install java-1.8.0-openjdk.x86_64
# or
aptitude install java8-jdk

Create a symlink to wherever your /etc/bashrc or ~/.bashrc has export JAVA_HOME=/usr/local/jdk set to.

ln -s /usr/lib/jvm/jre-1.8.0-openjdk.x86_64 /usr/local/jdk

Install Apache Solr

Get the latest version of Apache Solor here:

http://lucene.apache.org/solr/mirrors-solr-latest-redir.html

cd /usr/local/src
wget http://mirror.nexcess.net/apache/lucene/solr/5.3.1/solr-5.3.1.tgz
tar zxfv solr-5.3.1.tgz solr-5.3.1/bin/install_solr_service.sh --strip-components=2
sh ./install_solr_service.sh solr-5.3.1.tgz
chkconfig --add solr

Now let's verify Solr is running.

systemctl status solr
#or
service solr status

Setup Apache Solr for Drupal

Get the latest Apache Solr Search and install the module as usual into your drupal installation.

cd DRUPAL_INSTALLATION
drush dl apachesolr --dev -y; drush en apachesolr_access, apachesolr, apachesolr_search -y;

Get the drupal apache Solr 5.x configuration files and copy them over to Solr configuration directory:

cd DRUPAL_INSTALLATION/sites/all/modules/contrib/
wget http://ftp.drupal.org/files/projects/search_api_solr-7.x-1.x-dev.tar.gz
tar xzvf search_api_solr-7.x-1.x-dev.tar.gz
#or
drush dl search_api_solr --dev -y
mkdir -p /var/solr/data/drupal/conf
cp search_api_solr/solr-conf/5.x/* /var/solr/data/drupal/conf
chown -R solr:solr /var/solr /opt/solr

Now we create an Solr 5.x core for drupal--which we'll use the conf files copied over from above.

sudo /opt/solr/bin/solr create -c drupal

Add your server IP and YOUR IP to the Solr server whitelist

vi /opt/solr/server/etc/jetty.xml

Search for:

<New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>

Replace with:

<!-- Solr IP whitelist  -->
<New class="org.eclipse.jetty.server.handler.IPAccessHandler">
  <Call name="addWhite">
    <Arg>127.0.0.1</Arg>
  </Call>
  <Call name="addWhite">
    <Arg>YOUR.IP.ADDRESS.HERE</Arg>
  </Call>
  <Set name="handler">
    <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
  </Set>
</New>
<!-- / Solr IP whitelist  -->

Start Solr server

systemctl start solr.service
or
service solr start

That should take care of the hard part...

We can check Apache Solr interface here: http://localhost:8983/solr/#/

NOTE: The URL you're going to put in for Drupal's Apache Solr Search module is this:

http://127.0.0.1:8983/solr/drupal

After all this, you'll probably also want to install Drupal's Search API Solr search

So that's it, and that's that...

Don't forget to firewall protect port 8983 from public access. You can use CSF for that.

Tags: apache apache solr Drupal Server admin