Solr + Tomcat 6: install + setup guide

April 30th, 2009  |  Published in Uncategorized  |  2657 Comments

I’ve been playing around with Solr at work for a project I am working on, and figured it might be beneficial to others to post some of the install pains I’ve experienced with Tomcat 6. If you are using Tomcat 5, then this guide might work for you. It is not accurate for Tomcat 6 however.

A Bit of Background:
Solr is an open source enterprise search server based on the Lucene Java search library, with XML/HTTP and JSON APIs, hit highlighting, faceted search, caching, replication, a web administration interface and many more features. It runs in a Java servlet container such as Tomcat.

Install Steps:
Here are the install steps more or less that I went through (on OSX, although that shouldn’t matter too much):

Solr:
1. Download your Solr binary, I got version 1.3.0 from here.
2. tar xzf it to your working directory, something like /usr/local, or /opt/local. Make sure you chown the resulting directory to the proper owner.

Tomcat (If you already have Tomcat running, skip this step):
1. Download your tomcat binary build. I got version 6.0.18 from here.
2. tar xzf it to your working directory, something like /usr/local, or /opt/local. Make sure you chown the resulting directory to the proper owner.
4. There are two env variables that are required for Tomcat to run: CATALINA_HOME and JAVA_HOME. I made a couple of scripts to start and stop tomcat where I set those. The scripts look something like:

#!/bin/sh
export CATALINA_HOME=/opt/local/apache-tomcat-6.0.18
export JAVA_HOME=/usr
$CATALINA_HOME/bin/startup.sh

and

#!/bin/sh
export CATALINA_HOME=/opt/local/apache-tomcat-6.0.18
export JAVA_HOME=/usr
$CATALINA_HOME/bin/shutdown.sh

Don’t forget to make them executable:

chmod ug+x yourDir/start_tomcat yourDir/stop_tomcat

Solr+Tomcat: This part may be the most important one for actually getting solr to work with Tomcat
1. Copy from your SOLR_HOME_DIR/dist/apache-solr-1.3.0.war to your tomcat webapps directory: $CATALINA_HOME/webapps/solr.war – Note the war file name change. That’s important.
2. Create your solr home directory at a location of your choosing. This is where index data will be held and where the configuration for that solr install resides. I have it in a completly separate location on my file system so it was important for me to be able to do that. The easiest way to do this is to copy the SOLR_HOME_DIR/examples/solr directory to wherever it is you want your solr home container to be.
3. Start tomcat. Note this is only necessary to allow tomcat to unpack your war file. If you look under $CATALINA_HOME/webapps there should now be a solr directory.
4. Stop tomcat.
5. Go into that solr directory and edit under WEB-INF/web.xml. Scroll down until you see an entry that looks like this:

  <!-- People who want to hardcode their "Solr Home" directly into the
     WAR File can set the JNDI property here...
 -->
<!--
  <env-entry>
     <env-entry-name>solr/home</env-entry-name>
     <env-entry-value>/Path/To/My/solr/Home/solr/</env-entry-value>
     <env-entry-type>java.lang.String</env-entry-type>
  </env-entry>
-->
  

Uncomment that env-entry and change the env-entry-value to point to wherever it is you copied that solr home from the example dir in step 2.
6. Start Tomcat again, and things should be going splendidly. You should be able to verify that solr is running by trying the url http://localhost:8080/solr/admin/.

Enjoy.

Responses

  1. Steve says:

    May 26th, 2009 at 12:12 pm (#)

    thanks for the walkthrough!

  2. Chantal says:

    July 29th, 2009 at 4:46 am (#)

    It is not necessary to hack the web.xml.

    Consider the discussion in
    http://markmail.org/message/2nyp2nzoxu427js5

    and also
    http://wiki.apache.org/solr/SolrTomcat

    Something like
    export JAVA_OPTS=”$JAVA_OPTS -Dsolr.solr.home=/my/custom/solr/home/dir/”
    is probably the best way to set the solr.home variable if you want to leave the solr.war untouched (easy update process).

  3. Suresh says:

    August 18th, 2009 at 12:25 am (#)

    Thanks for the given steps

  4. Tushar says:

    November 12th, 2009 at 6:29 am (#)

    Hi,

    I followed your steps but then also I am getting this error :

    INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/solr] has not been started
    12 Nov, 2009 5:56:39 PM org.apache.solr.core.SolrResourceLoader locateSolrHome
    INFO: Using JNDI solr.home: /opt/local/solr/examples/solr
    12 Nov, 2009 5:56:39 PM org.apache.solr.core.SolrResourceLoader <init>
    INFO: Solr home set to ‘/opt/local/solr/examples/solr/’
    12 Nov, 2009 5:56:39 PM org.apache.catalina.core.StandardContext start
    SEVERE: Error filterStart
    12 Nov, 2009 5:56:39 PM org.apache.catalina.core.StandardContext start
    SEVERE: Context [/solr] startup failed due to previous errors

    Anybody who got the same error while starting solr .. plz help me with this one

    Thanks in advance :)

  5. CraftyFella says:

    December 30th, 2009 at 10:36 am (#)

    Hi,

    I’ve an updated version of the above for Solr 1.4 on the windows stack: Hope you find it useful:

    http://craftyfella.blogspot.com/2009/12/installing-solr-14-on-windows-xp-step.html

  6. Hirav says:

    May 14th, 2010 at 4:14 am (#)

    Hi I am not able to configure SOLR in windows. Getting some exception

    HTTP Status 500 – Severe errors in solr configuration.

    <abortOnConfigurationError>false</abortOnConfigurationError> in null ———————————————————————-java.lang.RuntimeException: Can’t find resource ‘solrconfig.xml’ in classpath or ‘solr/conf/’,

    If any idea please help me..

    Thanks in advance,
    Hirav Oza