Sunday, July 1, 2012

Installing Apache Solr 3.6 on Tomcat 7.0.28 under Mac OS X 10.7 Lion

Introduction

As this took me some maddening hours I write a post on my experience of installing Apache Solr 3.6 on a Tomcat 7.0.28 server under Mac OS X 10.6 Lion.
The goal of this installation was to provide the Solr search functionality in a Drupal project I'm doing.

Tomcat Installation

The Tomcat installation went actually quite fine. A good description of what has to be done has been provided by Wolf Paulus: "Installing Tomcat 7.0.x on OS X" which was my starting point.
Step by step I did the following:
1) I downloaded the latest Tomcat release from this locationto the Download directory of my Mac user
2) I unzipped the downloaded file in the download location - i.e. "Download" folder of my user. This creates a new directory named "apache-tomcat-7.0.28"
3) As decribed in Wolf Paulus' blog, I copied the "apache-tomcat-7.0.28" directory to the directory "/usr/local/".
Note: Wolf creates the directory "/usr/local/", but this existed on my macbook already...
4) I renamed the directory "/usr/local/apache-tomcat-7.0.28" to "/usr/local/Tomcat".

Note: up to here I didn't use the terminal, but did everything I did via the file browser muCommander

5) Now the terminal comes into play to take directory ownership:
$ sudo chown -R Wolfi /usr/local/Tomcat
and...
6) to make all scripts executable:
$ sudo chmod +x /usr/local/Tomcat/bin/*.sh
7) I followed Wolf's advice to control the Tomcat server via Tomcat Controller, configured it according to my system environment
8) Et voila, the server runs at http://localhost:8080/

Solr Installation

So much for the easy part...

To find a good step by step description of the Solr installation under OS X Lion was not so simple. I found the follwoing resources which were helpful:


  • First of all stop your Tomcat server


Now step by step:
1) Choose the appropriate file you need and download latest Solr release. In my case this was Solr 3.6.0 which is available here. I choose to download the fileapache-solr-3.6.0.tgz
2) Unpack the compressed file at a suitable location. In my case this was my "Download" directory. The directory has the name "/Download/apache-solr-3.6.0/"
3) After unpacking I checked if the package worked in general by starting the test server which is located in the directory "Download/apache-solr-3.6.0/example/". Change in the terminal to the directory where start.jar is located and execute (see SolrTomcat Wiki):
$ java -jar start.jar
4) I interpreted the instructions in "Installing Solr instances under Tomcat" in the SolrTomcat Wiki such that I copied the directory "/Download/apache-solr-3.6.0/example/solr/" to "/usr/local/solr/".
5) Copied the file "apache-solr-3.6.0.war" from "/Download/apache-solr-3.6.0/dist/" to "/usr/local/solr/" and renamed to "solr.war".
6) Create a new folder "data" in your new solr directory - i.e. "/usr/local/solr/data/"
7) Edit the configuration information in file "/usr/local/solr/conf/solrconfig.xml/". Change the variable <dataDir> in the file to your equivalent of:
<dataDir>${solr.data.dir:/usr/local/solr/data}</dataDir>
8) Create a solr configuration file called "solr.xml" in the (your equivalent of) directory "/usr/local/Tomcat/conf/Catalina/localhost/". Enter the following XML-code pointing the docBase location to the actual directory. In my case:
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="/usr/local/solr/solr.war" debug="0" crossContext="true">
<Environment name="solr/home" type="java.lang.String" value="/usr/local/solr" override="true"/>
</Context>
9) Start your Tomcat server
10) If everything went right (what it did in my case) you can start the solr instance will be available by calling in the browser:
http://localhost:8080/solr/
You will see a welcome screen showing "Welcome to Solr". The admin page is available at
http://localhost:8080/solr/admin


I hope my blog helps and you get through the steps successfully.

All the best