Skip to main content
knackforge blog knowledge base

Configure Apache Solr with Tomcat

At many times Drupal Architects prefer to go with Apache Solr instead of Drupal core search. I am no outlander to this scenario, but this time it was a new requirement. By default the Apache Solr relies on Jetty server to index and retrive items during the search. My need was to use Tomcat server in the place of Jetty. The first glance proved it was an easy task, but latter the tough fight started.

Initially I had the reference from many sites about how to integrate Apache solr with Tomcat. Alas, none had the elucidation to provide a end to end solution. Hence I would like to write one on my own.

Downloading and Starting Tomcat

Step 1: Download the Apache Tomcat Server from its official site. I would insist you to do this rather than installing via packet manager.

Step 2: Extract the folder in the /usr/share/. On multi site environment this would help to run the tomcat as a single instance.

Step 3: Now get into the Tomcat folder and see for bin folder. Ensure that you have a bin folder there. If you don't find bin it implies that you are in the wrong directory.

Step 4: Now cd into bin folder, and issue   $sudo -E ./ , this command will start the tomcat server.

-E gets the Java Environment.

If you are prompted with a message as below, it concludes the proper start of the Tomcat.

Using CATALINA_BASE:   /usr/share/tomcat7
Using CATALINA_HOME:   /usr/share/tomcat7
Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
Using JRE_HOME:        /usr/lib/jvm/java
Using CLASSPATH:       /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
If you are Prompted with  "JAVA_HOME or JRE_HOME not being defined" then you need to do
$ sudo export JAVA_HOME=/usr/lib/jvm/java 

Configuring Tomcat with Apache Solr

Step 5: The actual integration of Apache Solr with Tomcat starts here. 

Managing Tomcat7 application

sudo cp -R apache-solr/example/solr/ /usr/share/tomcat7/solr/
sudo nano /etc/tomcat7/Catalina/localhost/solr.xml
and paste
<role rolename="admin"/>
<role rolename="manager"/>
<user username="username" password="password" roles="admin,manager"/>

Linking Drupal 7 with a running Apache Solr

sudo cp apachesolr/schema.xml /usr/share/tomcat7/solr/conf/schema.xml

sudo cp apachesolr/solrconfig.xml /usr/share/tomcat7/solr/conf/solrconfig.xml

sudo cp apachesolr/elevate.xml /usr/share/tomcat7/solr/conf/elevate.xml

Checking and Troubleshooting 

Now set the port as 8080 in the apache solr configuration page ie: https://localhost:8080 and test the connection. If you are prompted with no errors, it implies the successfull integration of tomcat with solr.

If not please check the permissions and to be in the best case use the below mentioned one

sudo chown -R tomcat7:root /usr/share/tomcat7/solr/ 


Note: You can make use of this blog also with Drupal 6+, Apache solr 1.3+ and Tomat 6+