Apache Solr, Part II: Installing Solr with Tomcat

In Part I, I gave a sneak preview of the benefits of using Solr directly over using ColdFusion 9’s integrated implementation. Here, in part II, is a quick start guide to getting Solr up and running independently.

Solr, like ColdFusion, is a Java application that needs to run in a sevlet container such as Apache Tomcat, Resin, JRun or Jetty.

This post will get Solr up and running in Tomcat 6.

Step 1, Install Tomcat

If you’re not running it already, install Tomcat. In Ubuntu, you can install tomcat with the following command:

apt-get install tomcat6

If you’re on Windows, there is a binary installer. Head over to the Tomcat 6 downloads page and get the ‘32-bit/64-bit Windows Service Installer’: http://tomcat.apache.org/download-60.cgi. Other Unix flavours may have there own packages, only a google away.

For the rest of this guide, I will presume that Tomcat is installed and listening on port 8080. Visiting, http://localhost:8080/, should give you a Tomcat welcome page.

Step 2, download and deploy Solr

Head over to http://lucene.apache.org/solr/ and download the latest stable release. At the time of writing this guide, the latest was 1.4.1.

Extract the Solr .war file, {downloaded zip}/dist/apache-solr-1.4.1.war, to the Tomcat webapps directory, location of which may vary:

Windows default: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\
Ubuntu default: /var/lib/tomcat6/webapps/

Tomcat should automatically unpack this .war file for you and create a new directory within webapps, ‘apache-solr-1.4.1’, which contains all the code for Solr to run as a web application.

Step 3, configure Solr

Create a new configuration directory for your solr instance, anywhere you like. For this tutorial, I shall presume that one has been created in /{tomcat dir}/conf/solr/.

Copy the contents of {downloaded solr zip}/example/multicore into your new config directory. This is a basic configuration for Solr running with multiple cores (a core is equivalent to the ColdFusion search collection). We’ll get deeper into these files in later posts, but for now they’ll serve as a base configuration.

Step 4, configure Tomcat

Finally, we configure Tomcat to be able to present Solr at some uri, e.g. http:// localhost:8080/solr/, loading the configuration that we created in Step 3.

Open up {tomcat dir}/conf/server.xml and add the following Context definition to the Host element (replacing the ‘solr/home’ environment value to the directory you created in step 3):

<Host name="localhost" appBase="webapps" ...>
	<Context path="/solr" docBase="apache-solr-1.4.1">
		<Environment name="solr/home" type="java.lang.String" value="/var/lib/tomcat6/conf/solr" override="true" />
	</Context>
</Host>

Restart Tomcat and visit http://localhost:8080/solr/. With any luck you should see a Solr welcome page (and you are l33t).

Dominic