Install Apache Solr on Your Mac

I have made a lot of integrations against various Apache SOLR services, such as WebSOLR and Acquia Search. These services, does all the hard work for you, so you dont have to host the search index yourself.

When developing a website, and have to have a connection to those services, could be a pain in the… To let my work be more easy and straightforward, I have installed / configured a local Apache SOLR instance, for use for multiple cores.

Important!

This guide only works with 3.x branch of solr, since no valid schema.xml and solrconfig.xml has been released for the Drupal search_api module.

Multiple cores means that you will be able to create all the search indexes (cores), with their own config and schemas, you want to in a single Solr instance.

The whole SOLR instance will be available through a central webinterface..

Homebrew and other tools

There aren’t that much you will need to have installed, the “only” thing is Homebrew, in a single sentence it’s

Homebrew is the easiest and most flexible way to install the UNIX tools Apple didn’t include with OS X.

I will not go into how to configure / install homebrew.

Install Solr

It’s quite simple to install solr, since it’s just java so nothing is really compiled. But for now, since a version 4.x is released, which isn’t supported by search_api, we’re gonna install the latest 3.6.x release.

So we’re going to checkout the 3.6.1 release and install that.

Install Solr []
1
2
3
  cd $(brew --prefix)/Library/Formula
  git checkout 25b0587 /usr/local/Library/Formula/solr.rb
  brew install solr

After the installer is done, Apache Solr “almost” works, but we cannot really use it for anything since it’s installed with some example configurations, so we will change it to work with Drupal 7. At this point, we have to different approaches, either search_api or apachesolr modules.

Configure for multicore support

As a test, we’re going to hook this search up against Drupal 7, and we need either search_api_solr or apachesolr, which contains a few solr configuration files (schema.xml and solrconfig.xml). So first of all, we’re getting and extracting the needed module.

Create/go to a temporary folder in your home directory

[]
1
2
3
cd ~/
mkdir tmp
cd tmp

Get the module from Drupal.org

wget http://ftp.drupal.org/files/projects/search_api_solr-7.x-1.0-rc2.tar.gz

Or

wget http://ftp.drupal.org/files/projects/apachesolr-7.x-1.1.tar.gz

Extract the file

tar xf search_api_solr-7.x-1.0-rc2.tar.gz

Or

tar xf apachesolr-7.x-1.1.tar.gz

And for the real solr configuration we need to copy some default drupal settings. These settings tells solr how to configure solr to work with fieldtypes from Drupal and alot of stuff.

Go to where homebrew has installed Solr, change VER.SION to the actual version number, right now the version is 3.6.0, so the complete path would be cd $(brew --prefix)/Cellar/solr/3.6.0/libexec

cd $(brew --prefix)/Cellar/solr/VER.SI.ON/libexec

Make a copy of the provided example folder

cp -r example drupal
cd drupal/

Take backup of the default configuration files

cp solr/conf/schema.xml solr/conf/schema.xml.bak
cp solr/conf/solrconfig.xml solr/conf/solrconfig.xml.bak

Copy the solr configuration files from the Drupal module to the solr/conf directory.

cp ~/tmp/search_api_solr/*xml solr/conf/

Or

cp ~/tmp/apachesolr/solr-conf/solr-3.x/*xml solr/conf

To use solr as a multicore server, we will need to copy the solr.xml file configured for multicore support to the default folder

cp multicore/solr.xml solr/

The step below, could be repeated as many times, as you want separate search cores. Every instance should have it’s own name/folder like site1, site2, www_whatever_com or whatever, and remember to copy the complete solr/conf folder into every search core.

mkdir solr/site1
cp -r solr/conf solr/site1/

Now we need to edit the solr.xml file, solr needs to know about every search core you have created above.

nano solr/solr.xml

Remove everything from the file, and replace it with the codeblock below.

You will need to create an core element for every search core folder you have created above, and both element attributes (name and instanceDir) should be the actual folder name, as generated above.

solr/solr.xml []
1
2
3
4
5
6
<?xml version="1.0" encoding="UTF-8" ?>
  <solr persistent="false">
    <cores adminPath="/admin/cores">
      <core name="site1" instanceDir="site1" />
    </cores>
  </solr>

Now everything is configured and ready for starting. You will have to be placed in the correct folder.

cd $(brew --prefix)/Cellar/solr/VER.SI.ON/libexec/drupal

This command starts the solr server, and if you create a new cores, altering configuration or other changes, you will have to kill the process (done with control+c), and fireing the command again.

java -jar start.jar

If you see the Solr admin page Everything would be fine.

The complete path for the solr instance will be http://localhost:8983/solr/site1 or whatever you have set the core name to be.

Comments