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: http://download.nextag.com/apache/lucene/solr/1.3.0/apache-solr-1.3.0.tgz
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: http://apache.deathculture.net/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
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.