Setting up Drupal 6 with Apache Solr on Tomcat 6 and Ubuntu 9.10 (Karmic Koala)

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">
<Environment name="solr/home" type="java.lang.String" value="/usr/share/tomcat6/solr" override="true" />
</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>
<role rolename="admin"/>
<role rolename="manager"/>
<user username="nick" password="ateneatech" roles="admin,manager"/>
</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-co...

Additional Step 7 : Make a second SOLR site

We are going to create a second configuration file and another apache solr directory for our site-specific files and insert the following configuration
sudo nano /etc/tomcat6/Catalina/localhost/customsite.xml

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





copy the example to a new directory called solr
sudo cp -R apache-solr-1.4.0/example/solr/ /usr/share/tomcat6/customsite/

Don't forget to copy the schema
sudo cp apachesolr/schema.xml /usr/share/tomcat6/customsite/conf/schema.xml
sudo cp apachesolr/solrconfig.xml /usr/share/tomcat6/customsite/conf/solrconfig.xml

And restart our tomcat service
/etc/init.d/tomcat6 restart

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?showC...

20 comments on Setting up Drupal 6 with Apache Solr on Tomcat 6 and Ubuntu 9.10 (Karmic Koala)

  1. manuee (not verified)
    Tue, 03/09/2010 - 01:53

    Many thanks for writing this up!

    Also it was a pleasure spending the evening with you guys, thanks again for leting me hang with you that evening while waiting for the plane!

    Hope all is well
    Manuel

  2. Nick
    Tue, 03/09/2010 - 03:28

    No problem at all! I enjoyed that whole drupalcamp alot, and let's see if we can be able to meet another time at some other drupal related event? Drupalcamp Madrid?! ;-)

  3. Onopoc (not verified)
    Tue, 03/09/2010 - 05:59

    Thanks Nick. I added your tutorial to the following page http://drupal.org/node/736782

  4. Tamara (not verified)
    Thu, 03/11/2010 - 16:57

    Hello,
    Thank you very much for the instructions. Well written and complete. I sailed through them and had Solr running in no time on Ubuntu 9.10.

  5. PWolanin (not verified)
    Tue, 03/30/2010 - 20:43

    Why would you make two copies of the Solr war instead of using the solr multi core feature to serve the 2 indexes at different paths?

  6. Steve (not verified)
    Wed, 04/07/2010 - 00:57

    Looks like you're missing a step in Step 4 to extract the apache-solr-1.4.0.tgz file before copying the solr app to the Tomcat directory.

  7. Nick
    Wed, 04/07/2010 - 09:58

    @PWolanin I'm looking into this and will update the guide whenever I get this clear :-) Thanks for your tip!

    @Steve Thanks for that, I added the missing extract rule

  8. Ian King (not verified)
    Thu, 04/22/2010 - 01:01

    I can see the solrdev and solrprod paths in the Tomcat web application manager but cannot start either of them.

    the message I get is:

    FAIL - Application at context path /solrdev could not be started

    Any ideas?

    I'm using Ubuntu server 9.10 which had Tomcat installed as default

    Any thoughts?

  9. Nick
    Thu, 04/22/2010 - 01:05

    Do you have the correct permissions?
    I would suggest you try to start 1 solr instance at a time. If this works you can extend this to another one.

  10. Michael K (not verified)
    Mon, 05/03/2010 - 05:39

    Thanks for such a helpful document!

    I have a couple minor corrections to offer your last point #7:

    Copy the example to a new directory called customsite. Issue this command from your home directory:

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

    Don't forget to copy the schema. Issue this command from your modules directory:

    sudo cp apachesolr/schema.xml /usr/share/tomcat6/customsite/conf/schema.xml

    sudo cp apachesolr/solrconfig.xml /usr/share/tomcat6/customsite/conf/solrconfig.xml

  11. Anonymous (not verified)
    Fri, 05/14/2010 - 00:31

    Correct me if I'm wrong
    Ubuntu 10.04, steps 1-5:
    sudo tasksel install tomcat-server
    sudo aptitude install solr-tomcat

  12. Nick
    Fri, 05/14/2010 - 12:58

    Careful for the people that don't read! :-) This sudo tasksel install tomcat-server only works with ubuntu 10.04! (because there is a newer version shipped in the distribution)

    Ocdevel explained how to do this on 10.04.
    http://ocdevel.com/blog/installing-apachesolrmodule-ubuntu-1004

  13. Steve (not verified)
    Thu, 06/17/2010 - 01:46

    I got this running in a multi-core environment with Tomcat, and one thing I noticed was that your path for the Tomcat manager app seems to be incorrect. When I go to http://localhost:8080/manager/ I get a 404 error that "The requested resource (/manager/) is not available", but when I go to http://localhost:8080/manager/html/ it comes up fine.

  14. remlabm (not verified)
    Wed, 06/30/2010 - 22:44

    when setting up multiple sites its better to configure your data location per site so they are not call combined in one directory. by default solr keeps everything in solr/data/

    you can edit the solrconfig.xml for each site look for tag. You can comment it out. this will make solr store data in each site directory instead of one directory.

    thanks for the tutorial. was great help in getting my solr project off the ground.

  15. Nick
    Wed, 06/30/2010 - 22:47

    It's even better to follow the multi core approach as seen here :
    http://www.opensourcecatholic.com/blog/oscatholic/setting-apache-solr

    Goodluck ! :-)

  16. lee (not verified)
    Wed, 07/07/2010 - 16:30

    Thanks very much for the instructions. Well written and complete. I sailed through them and had Solr running in no time on Ubuntu 9.10.

  17. EvanDonovan (not verified)
    Fri, 07/09/2010 - 17:39

    If you want to allow access to port 8080 only to the local subnet, I believe the following iptables command will work:

    iptables -A INPUT -s 192.168.0.0/24 -p tcp -m tcp --dport 8080 ACCEPT.

    For more info on iptables see http://www.higherpass.com/linux/Tutorials/Iptables-Primer/3/.

  18. EvanDonovan (not verified)
    Fri, 07/09/2010 - 18:08

    I had an issue in which I could not access the manager app at http://localhost:8080/manager. However, it was accessible at http://localhost:8080/manager/html.

    See http://www.mail-archive.com/users@tomcat.apache.org/msg36324.html for more information.

  19. EvanDonovan (not verified)
    Fri, 07/09/2010 - 18:24

    As described on http://drupal.org/node/343467, you will need to get the SolrPhpClient library in order for the module to interface with Solr.

    You can checkout via SVN using the following command:

    svn export -r22 http://solr-php-client.googlecode.com/svn/trunk/ SolrPhpClient

  20. EvanDonovan (not verified)
    Fri, 07/09/2010 - 19:42

    For Solr to run properly on my Ubuntu install, since apt-get had created a tomcat6 user & group, I had to chown the /solr directory under /usr/share/tomcat6 to "tomcat6:tomcat6" or else Solr could not properly create its data directory.

    I don't know why this was, but it seems to have worked.

  21. Post new comment

    The content of this field is kept private and will not be shown publicly.
    • Web page addresses and e-mail addresses turn into links automatically.
    • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
    • Lines and paragraphs break automatically.

    More information about formatting options