ideas, experiments, work in progress, freebies & our thoughts on cutting edge tech

Installing Lucene-solr with tomcat on ubuntu

This article explains steps to install Solr -Lucene search engine under Tomcat on ubuntu.Also important checks to avoid spending a lot of time in debugging are mentioned where-ever needed.


First make sure you have latest java SDK installed.

Using –    dpkg –get-selections | grep sun-java

This may give you following result if java is already installed

sun-java6-bin          install
sun-java6-jdk         install
sun-java6-jre          install

If not, Install it using – apt-get install sun-java6-jdk

Make sure:- java was installed properly. check version of java installed with command – java version Or java showversion

Add below line in your “.bashrc” to set JAVA_HOME variable tomcat needs it.

export JAVA_HOME=/usr/lib/jvm/java-6-sun


Install Tomcat 6 with-

apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-user tomcat6-docs tomcat6-examples

Also install MYSQL java driver (if you need connecting to RDBMS MYSQL) with –

apt-get install libmysql-java

Once tomcat is installed make sure its installed properly by doing – curl http://localhost:8080

In above command use the port number configured for tomcat connector listens for HTML1.1. Check for it in”server.xml” under “/usr/lib/tomcat6/conf”

curl shall fetch html page showing “It works” heading and some instructions.


If everything is good till now, its time to install Solr.

a) Download solr with-

wget -c

uncompress it with – unzip

b) Now copy the .war file from solr folder to tomcat webapps folder.

cp ~/apache-solr-1.4.1/dist/apache-solr-1.4.1.war /var/lib/tomcat6/webapps/solr.war

c) Also copy solr files as below-

cp -R ~/apache-solr-1.4.1/example/solr/ /var/lib/tomcat6/solr/

This shall copy “bin” and “conf” folder and readme.txt to “/var/lib/tomcat6/solr/”

“conf” folder shall have following files –

  • -(make sure this file has write permissions for tomcat)
  • elevate.xml
  • mapping-ISOLatin1Accent.txt
  • protwords.txt
  • schema.xml
  • scripts.conf
  • solrconfig.xm
  • spellings.tx
  • stopwords.tx
  • synonyms.tx
  • xslt (folder)
  • my-data-config.xml (data config XML for your solr will need to edit this file so you can import mysql data in to solr)

d) Create the “solr.xml” file under “/var/lib/tomcat6/conf/Catalina/localhost/” with –

vi /etc/tomcat6/Catalina/localhost/solr.xml

Note:- XML file name under “/var/lib/tomcat6/conf/Catalina/localhost/” will be the path to access your solr instance like – http://localhost:8080/solr/

Add below contents in “solr.xml”

<Context docBase=”/var/lib/tomcat6/webapps/solr.war” debug=”0″ privileged=”true” allowLinking=”true” crossContext=”true”>
<Environment name=”solr/home” type=”java.lang.String” value=”/var/lib/tomcat6/solr” override=”true” />

In above code set value of solr home to where you copied the Solr files in step (c)

Change directory to “/var/lib/tomcat6/solr/” and create data folder with “mkdir data”

Make sure the tomcat has write permissions to “data” folder.

This completes solr installation .make sure it works by browing here “http://localhost:8080/solr”.

This shall give you html page with meassge “Welcome to Solr” with link to solr admin page.

e) Make sure contents in solrconfig.xml in “/var/lib/tomcat6/solr/conf” is correct and what you want for your solr instance .Check that requestHandler with dataimport handler is defined this is important to import data from mysql.

f) Also make sure that “/var/lib/tomcat6/solr/bin” contains MySQL java connector jar, Else while dataimport it may throw exception that JDBC driver not found.

g) If you want another instance of Solrr for development purpose –

-Copy “solr.xml” to “solrdev.xml”  in “/etc/tomcat6/Catalina/localhost/”.
-Also duplicate “solr” folder to “solrdev” in “/var/lib/tomcat6/”.
-Edit “solrdev.xml” to set solr home to “/var/lib/tomcat6/solrdev”.
-Edit “solrdev.xml” from “/var/lib/tomcat6/solrdev/conf” to use respecive “my-data-config.xml”
This instance can be accessed with “http://localhost:8080/solrdev”

Final step, restart Tomcat and check it here “http://localhost:8080/solr/”
use command “/etc/init.d/tomcat6 restart”

Here after refer to following links to successfully import data from MYSQL
For quick review;amp;pli=1?

14 thoughts on “Installing Lucene-solr with tomcat on ubuntu

Your email address will not be published.