Solr is an awesome app built on top of Lucene for fulltext search. However, setting it up can be a pain if you don’t find the right guide, or if you miss some small detail. So, here is my attempt to document the process of setting up solr in development and production using a rails app as an example.
Solr and Lucene are java apps, so you need java to get this stuff working, I installed sun-jdk just to play it safe, as far as I know it works well even with openjdk.
Steps to setup solr on production
- Install Sun JDK:
Download and setup tomcat: you’ll need to setup tomcat version 6.0 for your production server. Download the latest V6 tomcat files from http://tomcat.apache.org/download-60.cgi. Now, extract them into
Download or build the solr war files and copy them to
/apps/solr. You can find the links at: http://lucene.apache.org/solr/ or http://www.apache.org/dyn/closer.cgi/lucene/solr/. The war file is usually in a folder called
distand has a filename like
Create a file ~/apps/tomcat/conf/Catalina/localhost/solr-appname.xml with the following content
Steps till this point are the same for any kind of solr installation, be it for a rails or any other app.
- I use the sunspot_rails gem in my rails application, when using this, you can run
rails g sunspot_rails:installto create a
config/sunspot.ymlfile. Once you have the config file, change the production config values to point to the right port and path, e.g:
- Run the
bundle exec rake sunspot:solr:startcommand once, on the development machine, to generate the solr configuration files. And push this code to the production server.
That’s all. Setting solr is not very straightforward, but once you have it set up, it’s very easy to setup additional apps with the same solr server.
On a development machine, all you need to get solr working is: install java (check step 1) and setup sunspot (check step 5), and start the solr server with
bundle exec rake sunspot:solr:start