Drupal + apachesolr + tomcat notes

Submitted by jay on 13 March, 2009 - 13:15

I recently setup a Drupal 6.x installation with the apachesolr module. It was not as straightforward as I was expecting so I've made a few notes here. The most frustrating part is the Tomcat & Solr setup, after that the Drupal module works flawlessly.

I used this wiki page about Solr and Tomcat as a basic guide. First thing to do is to download and setup tomcat. I used the setup script we use at work for Tomcat (available here) to download and install Tomcat 5.5.27 in /usr/local/tomcat. Note that you can use any servelet container like Jetty, JBoss etc.

Next, I downloaded solr from http://people.apache.org/builds/lucene/solr/nightly/. I grabbed the most recent tarball from there and unpacked it to /tmp.

I prepared a directory /usr/local/solr for the files from that tarball and made sure it was owned by the tomcat user that was created with the install script. I then copied the dist/apache-solr-nightly.war file from the unpacked tarball in /tmp to /usr/local/solr/solr.war. I also copied the example/solr directory to /usr/local/solr per the wiki instructions.

From there I setup a context fragment for solr in /usr/local/tomcat/conf/Catalina/localhost/solr.xml that pointed to /usr/local/solr per the wiki instructions. I also put a startup parameter in /usr/local/tomcat/bin/setenv.sh: -Dsolr.solr.home=/usr/local/solr/ as I'm not sure which of those overrides the other (the context or directive).

With all that done, I restarted Tomcat and held my breath in anticipation. Alas, Tomcat complained giving errors like this one:

java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFctory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom
javax.xml.xpath.XPathFactory.newInstance(Unknown Source)

After a little searching I found this page:Failed to create an XPathFactory for the default object model. The author explains that Tomcat's version of the library might cause problems after upgrades etc. I hazarded a guess and moved Tomcat's common/endorsed/xml-apis.jar to xml-apis.jar.bak and gave it another restart. It worked!

Finally, because this solr instance was only being setup for Drupal, and because the site in question did not require Tomcat for anything else, I edited /usr/local/tomcat/conf/server.xml and added address="127.0.0.1" parameters to the connectors on ports 8080 and 8443. That change ensured that only services running locally, like apache, would be able to connect to tomcat for solr usage.

With all that done, the apachesolr setup in Drupal was a breeze. Just remember to do the SVN checkout per the module's README.txt. I copied the schema.xml and solrconfig.xml files from the module's directory to /usr/local/solr/conf (overwriting the existing versions). I made sure to chown -R tomcat:tomcat /usr/local/solr and restarted Tomcat one last time. I made sure that tomcat would start up on boot on the CentOS 5 host using "chkconfig tomcat on" ("update-rc.d tomcat defaults" for Debian & derivatives, which I prefer working with).

After that, I logged in to Drupal and configured the module. Tomcat listens on 127.0.0.1:8080, so localhost and 8080 work. The rest I left at the default settings. Under the index tab, I chose to rebuild indexes seeing only a few items (63) that needed indexing. I ran cron a few times and the index was populated with 3300 or so items.

Hope this is helpful to anyone else wishing to setup Tomcat with Solr, and those who are trying to use Solr with the apachesolr module for Drupal.