Setting up multicore Apache Solr on OS X using Homebrew

drupal planet, drupal 7, drupal 6

Realityloop is currently working on a client project the involves adding a new region to a site and having region specific content, the client is already using Apache Solr to improve the search of their products. Deciding I needed to set up Apache Solr locally for testing to ensure that each region only returned results for it's products, using Homebrew here is how I went about it.

For those that don't know Solr is an open source enterprise search platform from the Apache Lucene project. Its major features include powerful full-text search, hit highlighting, faceted search, dynamic clustering, database integration, and rich document (e.g., Word, PDF) handling. Providing distributed search and index replication, Solr is highly scalable. (learn more at Wikipedia)

The installation and setup process:

If you don't already have Homebrew installed you will need to follow the Homebrew installation instructions first.

Once you have Homebrew installed open the terminal application and type the following:

  1. brew install solr

This will install Solr to /usr/local/Cellar/solr/ inside this directory will be a subdirectory of the Solr [version], in my case 3.1.0.

You should now download the apachesolr drupal module to at least one local site as you require some of its files to properly configure solr for use with Drupal.

The Solr configuration files are stored at /usr/local/Cellar/solr/[version]/libexec/example as I wanted to set up a multicore instance I did the following:

  1. cd $(brew --prefix solr)/libexec/example
  2. cp -R multicore multicore.bak
  3. cd multicore

Edit the solr.xml to update the core names

  1. nano solr.xml

And update the core names like follows:

Save the changes using CTRL+X then Y to confirm.

Now we need to copy the required files from the Drupal apachesolr module into the core directories, I am going to assume that the apachesolr module is stored at the following path ~/Sites/drupalsite/sites/all/modules/contrib/apachesolr/ and that our terminal instance is still in the multicore directory:

  1. cd core0
  2. cp ~/Sites/drupalsite/sites/all/modules/contrib/apachesolr/*.xml ./
  3. cd ../core1
  4. cp ~/Sites/drupalsite/sites/all/modules/contrib/apachesolr/*.xml ./

Now we are ready to start Solr using the multicore settings, you can do this from the terminal command line as follows:

$ java -Dsolr.solr.home=multicore -jar $(brew --prefix solr)/libexec/example/start.jar

You will now be able to access the Solr administration interface at http://localhost:8983/solr/

Within your Drupal site you need to enter the following for apachesolr settings

  • Solr host name:
  • Solr port: 8983
  • Solr path: /solr/[core name value]  (eg. /solr/

You can use multiple cores on the same site with the help of the Domain Access module

Simplifying things a little more:

We can go one step better and use launchd to make launching Solr much simpler as follows

  1. cd ~/Library/LaunchAgents
  2. nano com.apache.solr.plist

Paste the following, replacing [your-username] with your actual username :

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE plist PUBLIC
  3. "-//Apple Computer//DTD PLIST 1.0//EN" "
  5. <plist version="1.0">
  6. <dict>
  7. <key>Label</key>
  8. <string>org.apache.solr</string>
  9. <key>ProgramArguments</key>
  10. <array>
  11. <string>/usr/bin/java</string>
  12. <string>-Djetty.home=$(brew --prefix solr)/libexec/example</string>
  13. <string>-Djetty.logs=/var/logs/solr</string>
  14. <string>-Dsolr.solr.home=$(brew --prefix solr)/libexec/example/multicore</string>
  15. <string>-jar</string>
  16. <string>$(brew --prefix solr)/libexec/example/start.jar</string>
  17. </array>
  18. <key>ServiceDescription</key>
  19. <string>Solr</string>
  20. <key>WorkingDirectory</key>
  21. <string>/opt/local/share/solr</string>
  22. <key>UserName</key>
  23. <string>[your-username]</string>
  24. <key>GroupName</key>
  25. <string>staff</string>
  26. <key>RunAtLoad</key>
  27. <true/>
  28. </dict>
  29. </plist>

Now you can launch Solr using

  1. launchctl load -w ~/Library/LaunchAgents/com.apache.solr.plist

And quit it using

  1. launchctl unload -w ~/Library/LaunchAgents/com.apache.solr.plist

To go even further you can add this to your own web control script, I've attached mine below for you to model from.

Web services Startup script (rename to .sh instead of .txt)


For some reason, that doesn't work for me in the plist; I have to hard code the path. I kept getting <code>Unable to access jarfile $(brew --prefix solr)/libexec/example/start.jar</code>...

Submitted by Nicholas Thompson on February 21, 2013 - 11:16pm

Thanks for the tutorial but there is a slight missing bit of content:

And update the core names like follows:

Save the changes using CTRL+X then Y to confirm.

It looks like a missing tag or something! I can see it in the source anyway.

Submitted by Alastair on March 6, 2014 - 5:41am

Add new comment