Installing Solr on Tomcat

Last updated on
30 April 2025

CentOS:

This walk-through assumes you already have Tomcat installed. If you don't it is probably easier to just use WHM and install it there and rebuild apache. Point and click is what I say.

Once you have Tomcat installed you can verify its installation by going to:

domain.com:8080

You should see the default Tomcat page. If not, ask someone for help. If you don't, you are hurting the next person who comes along with the same issue. If we didn't want to help we wouldn't be Open Source.

Download your a copy of Solr. If you don't know where to get it, google it.

To make things easier now and in the future, find your Tomcat installation

$ locate tomcat {create a soft link like so:}

ln -s /my/tomcat/location /tomcat

If you did it right you should be able to just

$ /tomcat

in sshd and get to your directory.

I will be using the /lib directory for my example. If you don't have one, create it with mkdir /lib command.

1.) Extract Solr to temporary location, for my sake, I just get the zip file from Solr mirrors.

$ unzip apache-solr-1.4.1.zip /lib/

Build your Solr

$ cd /lib/solr
$ ant dist (you should see it building something.)

2.) Rename your war file for ease of use.

$ cd /lib/apache-solr-1.4.1
$ cd dist
$ mv apache-solr-1.4.1.war solr.war (this just renames it without asking you)
$ dir (check to make sure it worked. you should see solr.war)

3.) Copy solr.war to /lib/solr/example

$ cp solr.war /lib/solr/example
$ cd /lib/solr/example
$ dir (verify that the solr.war is in the directory, you should also see the familiar start.jar file there)

3.) Copy the xml files from your apachesolr location. Usually it will be:

cp /home/YOUR_NAME/www/modules/apachesolr/*.xml /lib/solr/example/solr/conf

4.) Create an xml file in Tomcat to tell it to run Solr at Tomcat start-up

$ cd /tomcat
$ cd /conf/Catalina/localhost
$ vi solr.xml

Paste this into your new file:

<?xml version="1.0" encoding="utf-8"?>
<Context docBase="/solr/example/solr.war" debug="0" crossContext="true" >
   <Environment name="solr/home" type="java.lang.String" value="/solr/example/solr" override="true" /> 
</Context>

The two values you should be customizing are Context::docBase (to point to your .war file) and Environment::value (to point to your solr directory). Note that in this example the .war file is in the solr directory, which is a fine pattern to follow.

{Press Escape Key and then :w} and then {Press Escape Key and then :q}

5.) Restart Tomcat using WHM for ease. It's under Restart Services. Then go here:

yourdomainname.com:8080/solr/admin

You may get this error:

<abortOnConfigurationError>false</abortOnConfigurationError> in null ------------------------------------------------------------- java.lang.RuntimeException: java.io.IOException: Cannot create directory: /usr/share/solr/data/index at org.apache.solr.core.SolrCore.initIndex(SolrCore.java:398) at org.apache.solr.core.SolrCore.<init>(SolrCore.java:546) at

Don't panic. I gatcha!

Go to solrconfig.xml again

$ cd /solr/example/solr/conf
$ vi solrconfig.xml

and modify this line:

<!--<dataDir>${solr.data.dir:./solr/data}</dataDir>-->

to

<dataDir>${solr.data.dir:./solr/data}</dataDir>

Restart Tomcat again and go here:

yourdomainname.com:8080/solr/admin

DO THIS IF YOU HAVEN'T ALREADY:

Go to your schema.xml file in /lib/solr/example/solr/conf:

$ vi schema.xml
Add this in the section just after

  <field dest="host" source="host"/>
  <field dest="segment" source="segment"/>
  <field dest="boost" source="boost"/>
  <field dest="digest" source="digest"/>
  <field dest="tstamp" source="tstamp"/>

Save it and exit {Press Esc Button) :w (Press Enter) then (Press Esc Button) :q (Press Enter)

If you are using Nutch then go here and install/configure nutch: http://groups.drupal.org/node/105774

Help improve this page

Page status: Not set

You can: