Installing Apache Solr on Tomcat

by John Entwistle | Developer

Apache Solr is a full text search engine that is highly customizable and includes support for faceted search. It can be used in place of the core Drupal search engine to provide users enhanced searching of your Drupal site. This post will guide you through the steps of installing Apache Solr and configuring the search engine to run efficiently through the Apache Tomcat webserver.

 

Install the Tomcat Webserver

 

Tomcat is a web server designed specifically to serve Java applications such as Apache Solr. First we will need to download and install the version of Tomcat that is appropriate for your system. This step assumes that you have the Java runtime installed and configured to run on your system.

 

To install the Tomcat, download the appropriate binary package and extract it into the /opt directory. Next move or symlink the extracted directory to /opt/tomcat. For example, to install Tomcat 6.0.35:

 

$ wget http://apache.cs.utah.edu/tomcat/tomcat-6/v6.0.35/bin/apache-tomcat-6.0.35.tar.gz
$ sudo mv apache-tomcat-6.0.35.tar.gz /opt && cd /opt
$ ln -s apache-tomcat-6.0.35 tomcat

Next we will need to set the $CATALINA_HOME environment variable to point to /opt/tomcat or the location to which you installed Tomcat. To do this, add the following line to /etc/profile or a similar startup script:

 

export CATALINA_HOME=/opt/tomcat

Upon re-sourcing the file you modified in the last step we'll be able to start and stop the Tomcat server using the following scripts:

 

$ sudo $CATALINA_HOME/bin/startup.sh
$ sudo $CATALINA_HOME/bin/shutdown.sh
 

Installing Apache Solr

 

The next step is to download and install the appropriate version of Apache Solr for your system. Extract the archive and copy the .war file to the webapps directory of your Tomcat installation, in our example this would look like:

 

$ wget http://mirrors.kahuki.com/apache//lucene/solr/3.5.0/apache-solr-3.5.0.tgz
$ tar -xzf apache-solr-3.5.0.tgz && cd apache-solr-3.5.0
$ sudo cp dist/apache-solr-3.5.0.war /opt/tomcat/webapps/solr.war

We also need to copy the Solr configuration from the example Solr setup:

$ cp -R /path/to/apache-solr-3.5.0/example/solr $CATALINA_HOME/solr

Note: If you are following this example and installing Solr version 3.5.0 as we are here this issue applies:  http://lucene.472066.n3.nabble.com/solr-VelocityResponseWriter-error-in-version-3-5-0-td3570020.html As described in the link, this is not an issue in other versions of Solr so if you are not using 3.5.0 you may skip the following steps. To fix, we just need to copy a few more directories from the Solr example:

 

$ cp /path/to/apache-solr-3.5.0/contrib $CATALINA_HOME/solr/contrib
$ cp /path/to/apache-solr-3.5.0/dist $CATALINA_HOME/solr/dist

After copying these directories we need to edit $CATALINA_HOME/solr/conf/solrconfig.xml and change all of the relative paths to the lib diretories to absolute paths pointing to the location of those directories in our installation.

 

Finally we'll need to let the Tomcat server know about the Solr webapp. To do this, we'll need to add a file to your Tomcat configuration as follows:

 

$ mkdir -P $CATALINA_HOME/conf/Catalina/localhost
$ cd !$
$ touch solr.xml

Now open solr.xml in your text editor of choice and add the following configuration:

 

<Context allowlinking="true" crosscontext="true" debug="0" docbase="</full/path/to/webapps/solr.war>" priviledged="true">
  <Environment name="solr/home" override="true" type="java.lang.String" value="</full/path/to/solr/>">
</Context>
 

We will now be able to restart the Tomcat server and access the Solr admin interface at http://localhost:8080/solr/admin/.

 

To find out more about indexing and searching Drupal content with Apache Solr, see my second post in this series.

 

apache solr, drupal, search, tomcat

Leave a Comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Fill in the blank
To prevent automated spam submissions leave this field empty.