Installing Apache Tomcat 6 and Solr nightly on Ubuntu 8.04

Getting Solr to play nice with Tomcat on Ubuntu was an interesting journey, I almost gave up entirely at one point. I'm compiling this how-to from tips I got from multiple websites. I'll try to make as complete a list as I can remember at the end of this post.

First off, forget about using the Ubuntu packages of Tomcat and Solr, they're broken, as well as outdated. Download the latest release of Tomcat from their site, and grab a nightly build of Solr from here using wget or whatever method you prefer. Untar both of them in your home directory.

tar xfzv apache-tomcat-6.0.18.tar.gz
tar xfzv solr-2009-04-06.tgz

Now, move Tomcat to wherever you want to have it installed, I chose to put it in /usr/local/tomcat6.

sudo mv apache-tomcat-6.0.18/ /usr/local/tomcat6/

Next, copy the Solr .war file from apache-solr-nightly/dist/ to the webapps/ directory of tomcat6/, and the example webapp from apache-solr-nightly/example/solr/ to the tomcat6/ root directory.

sudo cp apache-solr-nightly/dist/apache-solr-nightly.war /usr/local/tomcat6/webapps/solr.war
sudo cp -r apache-solr-nightly/example/solr/ /usr/local/tomcat6/solr/

Now that all the files are in place, we need to create a config file to run Solr.

sudo mkdir /usr/local/tomcat6/conf/Catalina/
sudo mkdir /usr/local/tomcat6/conf/Catalina/localhost/
sudo nano /usr/local/tomcat6/conf/Catalina/localhost/solr.xml

In this file, insert the following code:

<Context docBase="/usr/local/tomcat6/webapps/solr.war" debug="0" crossContext="true" >
   <Environment name="solr/home" type="java.lang.String" value="/usr/local/tomcat6/solr" override="true" />
</Context>

Edit your .bashrc file in your home directory and add the following to it:

export JAVA_HOME=/usr/lib/jvm/java-6-sun
export JAVA_OPTS="$JAVA_OPTS -Dsolr.solr.home=/usr/local/tomcat6/solr"

If all went well, you should be able to start Tomcat and browse to http://your.servers.ip:8080/solr/admin and see the Solr admin page.

/usr/local/tomcat6/bin/startup.sh

If this worked, great, but now it's time to get Tomcat to autostart itself when your server reboots. First, open a new script in your /etc/init.d/ directory.

sudo nano /etc/init.d/tomcat6

Insert the following code:

# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/lib/jvm/java-6-sun
export JAVA_OPTS="$JAVA_OPTS -Dsolr.solr.home=/usr/local/tomcat6/solr"

case $1 in
start)
   sh /usr/local/tomcat6/bin/startup.sh
   ;;
stop)
   sh /usr/local/tomcat6/bin/shutdown.sh
   ;;
restart)
   sh /usr/local/tomcat6/bin/shutdown.sh
   sh /usr/local/tomcat6/bin/startup.sh
   ;;
esac
exit 0

Finally, to make sure it autostarts, run this command:

sudo update-rc.d tomcat6 start 91 2 3 4 5 . stop 20 0 1 6 .

Congratulations! If you've followed this how-to exactly, you should have a working install of Apache Tomcat and Solr.

Links I got tips from:

http://wiki.apache.org/solr/SolrTomcat
http://www.tc.umn.edu/~brams006/solr_ubuntu.html
http://www.howtogeek.com/howto/linux/installing-tomcat-6-on-ubuntu/
http://lethain.com/entry/2009/mar/06/solango-and-tomcat-6-on-ubuntu-intrepid/
http://markmail.org/message/2xxiyry4y42hpodd
http://ubuntuforums.org/showthread.php?t=194559

And another for those wishing to receive training in administering Apache Tomcat:
http://marakana.com/training/tomcat/apache_tomcat_administration.html

Trackback URL for this post:

http://justin-hayes.com/trackback/1023

Comments

Anonymous's picture

Thanks for the walkthrough. I've been having trouble getting Solr to work on Tomcat too. Consistent and up-to-date information has been hard to find. Think my problem was that I was using a 5.X version of Tomcat - works fine now with 6.x. Cheers.

Justin's picture

You're right, the documentation out there is very inconsistent, out-of-date, and incomplete. Glad I was able to help.

Anonymous's picture

This is a very useful walkthrough, but I seem to be getting caught after having edited .bashrc; when trying to access the Solr admin page, I see the following:

HTTP Status 404 - /solr/admin
type Status report
message /solr/admin
description The requested resource (/solr/admin) is not available.
Apache Tomcat/5.5

Any advice you could offer would be greatly appreciated.

Justin's picture

I can't guarantee that my guide will work if you're using Tomcat 5.5. I'd recommend you switch to 6.

Anonymous's picture

What is the best way to go about doing this? I tried going through the installation of Tomcat 6 as you described it, but as you can see, Tomcat 5.5 was not overwritten - am I missing a step?

Justin's picture

The best thing to do would be to delete everything you installed and downloaded and start from scratch, in that case.

Anonymous's picture

Thanks a million! Great tutorial. Works perfect for Ubuntu 9.10.

NOTE TO OTHERS: I had to chmod 755 /etc/init.d/tomcat6 to get it to be executable. Then tomcat will survive a reboot.

Anonymous's picture

Thanks. Works Perfectly.

Post new comment

  • Allowed HTML tags: <a> <em> <strong> <b> <p> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can use BBCode tags in the text. URLs will automatically be converted to links.
  • You may use [inline:xx] tags to display uploaded files or images inline.
  • You may quote other posts using [quote] tags.
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.
  • You may insert videos with [video:URL]

More information about formatting options