During my last session on Drupalcamp in Barcelona I got the impression that there was a need for an updated guide on how to easily setup your own Apache Solr instance. If you want to see why you or your company would have the need for an improved search experience you can still see my presentation on slideshare : http://www.slideshare.net/nickvh/drupal-apachesolr

Previously I already wrote a Apache Solr Guide during my time at Krimson but this one is a bit outdated and because of this not 100% reliable anymore.

Also, on a side note : There are alot of interesting sessions about Apache Solr in the forthcoming Drupalcon San Francisco so I hope that my scholarship will be accepted to go there! Let’s pray. Or if one of you would be so free to give me some support to be able to attend it, it would be very appreciated ;-)

Here we go!

Step 1. Installing Tomcat

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-user tomcat6-docs tomcat6-examples

This command downloads and install the following packages tomcat6 : Servlet and JSP engine tomcat6-admin : Admin web applications tomcat6-common : Common files tomcat6-user : Tools to create user instances tomcat6-docs : Example web applications tomcat6-examples : Example web applications Start tomcat by typing

/etc/init.d/tomcat6 start

Step 2. Security

If you are using ip-tables and installing Apache Solr on an external server. Modify or add the following line to accept the port 8080

-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT

After installation type http://localhost:8080 or http://serverip:8080in your browser. Now you should see tomcat welcome page. (See included Image in the bottom)

PS: As noticed by Robert Douglass. Be careful when opening ports in public servers. Apache Solr Does NOT provide security by default so anyone is able to post data towards your system. Best is to add another rule where you only accept 8080 connections from a certain Ip-address.

Step 3. Downloading

Download apachesolr to your home directory for temporary reasons. (check for latest version or nightly build on http://apache.rediris.es/lucene/solr/ or http://people.apache.org/builds/lucene/solr/nightly)

cd ~/
wget http://apache.rediris.es/lucene/solr/1.4.0/apache-solr-1.4.0.tgz
tar -zxvf apache-solr-1.4.0.tgz

Step 4. Linking Tomcat6 with Apache Solr application

This should give you an idea on where your distribution installed tomcat6. Attention : If your path is different do not forget to also adjust this in the next steps.

whereis tomcat6

should show you

tomcat6: /etc/tomcat6 /usr/share/tomcat6

copy the war file to the webapps directory

sudo cp apache-solr-1.4.0/dist/apache-solr-1.4.0.war /usr/share/tomcat6/webapps/solr.war

copy the example solr application to a new directory called solr. We will change this example solr application later on to be viable for Drupal 6

sudo cp -R apache-solr-1.4.0/example/solr/ /usr/share/tomcat6/solr/

create our config file

sudo nano /etc/tomcat6/Catalina/localhost/solr.xml

And fill it with the following configuration :

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

Step 5. Managing Tomcat6 application

We want to see how and/or if our Solr application is running, we can do this by using the manager application. By default you don’t have access to this application so we have to modify the permissions.

sudo nano /etc/tomcat6/tomcat-users.xml

And modify it so it more or less reflects the same information as shown here.

<tomcat-users><br/>  <role rolename="admin"/><br/>  <role rolename="manager"/><br/>  <user username="nick" password="ateneatech" roles="admin,manager"/><br/></tomcat-users>

Drop Tomcat security so Solr can access /usr/share/tomcat6/solr

sudo nano /etc/default/tomcat6

And modify it so our security is disabled. Be careful if you are running on a server which you do not control 100%!

TOMCAT6_SECURITY=no

restart our tomcat service

sudo /etc/init.d/tomcat6 restart

surf to http://localhost:8080/manager/ and log in with your username and password from above and check if the solr instance is started. If not start and it and check wether or not you receive an error code! If your application is started, surf to http://localhost:8080/solr/admin and you should see a nice screen! (See included Image in the bottom)

Step 6. Linking Drupal 6 with a running Apache Solr

I assume you have Drush installed so we continue with downloading the apachesolr module. Execute this commando in the designated website.

drush dl apachesolr

let’s copy our schema that will customize our Apache Solr Instance so it fits the “Drupal” bill.

sudo cp apachesolr/schema.xml /usr/share/tomcat6/solr/conf/schema.xml
sudo cp apachesolr/solrconfig.xml /usr/share/tomcat6/solr/conf/solrconfig.xml

Tip: it might be a good idea to use symbolic links so we can easily update our modules and update our schemes if they change …you never know with open source ;-)

Additional : give the folder permissions!

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

Enable the module in the modules list and go to the config screen fill in the next parameters :

Host name of your Solr server, e.g. localhost or example.com (check the beginning, mostly localhost) Solr host name: localhost

Port on which the Solr server listens. Tomcat is 8080 by default. Solr port: 8080

Path that identifies the Solr request handler to be used. Solr path: solr

NOTE : For the creation of a second SOLR site it is recommended to follow the multi core step by step process which can be followed here : http://www.drupalconnect.com/blog/steve/configuring-apache-solr-multi-core-drupal-and-tomcat-ubuntu-910

Additional Step 7 : Make a second SOLR site

Deprecated for solr multi core guide above

Step 8: Be happy!

Happy solr’ing again with this updated guide!

Next Blogpost I will explain you how I made the example I shown on the Drupalcamp Barcelona. A very fast demo setup of a faceted search webshop in which we will be able to sort and lookup information about FC Barcelona football players! Using my own module of the Apache Solr for Ubercart and Drupal 6.

Sources :

  • http://krimson.be/articles/setup-drupal-6x-apache-solr-tomcat6-and-ubuntu
  • http://groups.drupal.org/node/25425/
  • http://wiki.apache.org/solr/SolrTomcat
  • http://yousefourabi.com/blog/2007/12/running-solr-on-debian-with-tomcat/
  • https://wiki.fourkitchens.com/display/TECH/Solr+1.4+on+Ubuntu+9.10?showComments=true&showCommentArea=true