Solr installation under Tomcat

This post is a guide for installing Solr under Tomcat server. The steps illustrated here are tested on Mac OS, but it should also work on linux and unix systems.

Download Tomcat and Solr
Download tomcat
Download solr
On unix like systems, Solr can be downloaded from command line

cd /Users/Edwin/
tar -xvf apache-solr-3.5.0-src.tgz 

Tomcat Set Up
Extract tomcat to

Edit /Users/Edwin/tomcat/tomcat6/conf/tomcat-users.xml to enable manager login as user “tomcat” and password “tomcat”, it could set to other user and password as you like for better security.The file should look like this after edit.

<?xml version='1.0' encoding='utf-8'?>
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  See the License for the specific language governing permissions and
  limitations under the License.
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary.
  NOTE:  The sample user and role entries below are wrapped in a comment
  and thus are ignored when reading this file. Do not forget to remove
  <!.. ..> that surrounds them.
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
<role rolename="manager"/>
<role rolename="admin"/>
<user username="tomcat" password="tomcat" roles="manager,admin"/>

Now, we can start the tomcat by run the below script

And then we visit localhost:8080

Building Solr
The below steps need to have jdk 1.6 and ant installed

Assume solr was downloaded extracted to /Users/Edwin/apache-solr-3.5/, do the below in the command line to build the solr example

cd /Users/Edwin/apache-solr-3.5/solr/
ant example

Run solr by issuing the below command in the command line and then visit localhost:8983/solr/admin

cd /Users/Edwin/apache-solr-3.5/solr/example
java -jar start.jar

Build the solr war file by

cd  /Users/Edwin/apache-solr-3.5/solr
ant dist

Installing Solr under Tomcat
With the above steps, we have built the Solr and the example. We are now ready to install the example as an instance under Tomcat

Do the below commands to create a solr home directory and copy the example/solr directory and the war file to there

mkdir /Users/Edwin/solr/ 
cp -r /Users/Edwin/apache-solr/solr/example /Users/Edwin/solr/example
cp /Users/Edwin/apache-solr/solr/dist/apache*.war  /Users/Edwin/solr/example/solr/solr.war

Open the file /Users/Edwin/solr/example/solr/conf/solrconfig.xml, find the tag and change that line to the below


Create a Tomcat context fragment file /Users/Edwin/tomcat/tomcat6/conf/Catalina/localhost/solr-example.xml

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

Restart the Tomcat

cd /Users/Edwin/tomcat/tomcat6/bin/

Go to localhost:8080/solr-example/admin to load the solr admin page.

When indexing data, solr creates data files in the directory /Users/Edwin/solr/example/solr/data which has to be writable by tomcat or any other users that is doing the indexing. The below will grant read, write and execute access to all users for every files under /Users/Edwin/solr/example

sudo chmod -R 777 /Users/Edwin/solr/example

This is convenient to solve permission issues during indexing data into solr, but it should only be used for convenience on DEV environment, never grant all access on prod environment.
See File ownerships and file permisions on Linux and unix like systems for more information.

Solr3.5 issue with Tomcat
For solr3.5, there is the below issue when trying to load the solar admin page

HTTP Status 500 - Severe errors in solr configuration. 
Check your log files for more detailed
information on what may be wrong. 
If you want solr to continue after configuration errors, change: 
<abortOnConfigurationError>false</abortOnConfigurationError> in solr.xml ------------------------------------------------------------- org.apache.solr.common.SolrException: 
Error loading class 'solr.VelocityResponseWriter' at
org.apache.solr.core.SolrResourceLoader.findClass( at
org.apache.solr.core.SolrCore.createInstance( at
org.apache.solr.core.SolrCore.createInitInstance( at
org.apache.solr.core.SolrCore.initPlugins( at
org.apache.solr.core.SolrCore.initPlugins( at

To fix this issue open the file /Users/Edwin/solr/example/solr/conf/solrconfig.xml and replace the line

<queryResponseWriter name="velocity" class="solr.VelocityResponseWriter" enable="${solr.velocity.enabled:true}"/>


<queryResponseWriter name="velocity" class="solr.VelocityResponseWriter" enable="${solr.velocity.enabled:false}"/>

Restart the Tomcat

This is a lib referencing issue of the VelocityResponseWriter which usually happen the solr installation under Tomcat. For a better explanation of this issue, see the post

Search within Codexpedia

Custom Search

Search the entire web

Custom Search