I was running Ubuntu 13.10 (saucy) and, for my sanity and system integrity, I always try to manage as many packages as I can through the actual Ubuntu/Debian package management system, APT. There are many great references out there – Ben Chavet’s article from Lullabot got me most of the way there – but I want to rehash it here quickly, with specific instructions for my software stack.
Unfortunately, as most installation guides note, the packages in many Linux distribution package archives tend to have older versions of Solr; Ubuntu’s saucy package archive has Solr 3.6. So in order to take advantage of the last couple of years of Solr development – as recommended by most Drupal-related references – Solr was the one exception where I installed the software manually outside of the package manager.
Reviewing the Software Stack
- Ubuntu 13.10 (saucy)
- Java 7 (openjdk-7 package)
- Tomcat 7 (tomcat7 package)
- Solr 4.8.1 (manual download/installation)
- Drupal 7.25
- Search API 7.x-1.11
- Search API Solr 7.x-1.4
We begin by installing Java from the command line.
sudo apt-get install openjdk-7
Now we can install Tomcat from the command line.
sudo apt-get install tomcat7
Once Tomcat is installed, we can verify that the Tomcat default web page is present by opening up a browser window and navigating to http://localhost:8080/.
Download the latest version of Solr 4.8.1 from http://lucene.apache.org/solr/, expand the archive, and copy Solr’s Java libraries to the Tomcat library directory.
sudo cp solr-4.8.1/dist/solrj-lib/* /usr/share/tomcat7/lib/
Next, copy Solr’s logging configuration file to the Tomcat configuration directory.
sudo cp solr-4.8.1/example/resources/log4j.properties /var/lib/tomcat7/conf/
We will also need to copy the Solr webapp to the Tomcat webapps directory.
sudo cp solr-4.8.1/dist/solr-4.8.1.war /var/lib/tomcat7/webapps/solr.war
Then, define the Solr context by modifying the solr.xml file.
sudo vim /var/lib/tomcat7/conf/Catalina/localhost/solr.xml
We just need a context fragment pointing to the webapp file from above and to the Solr home directory.
<Context docBase="/var/lib/tomcat7/webapps/solr.war" debug="0" crossContext="true"> <Environment name="solr/home" type="java.lang.String" value="/usr/share/tomcat7/solr" override="true" /> </Context>
To configure Solr, first create the Solr home directory.
sudo mkdir /usr/share/tomcat7/solr
Next, copy the Solr configuration files to the Solr home directory.
sudo cp -r solr-4.8.1/example/solr/collection1/conf /usr/share/tomcat7/solr/
Now we can verify that Solr is working by pointing our browser tohttp://localhost:8080/solr.
Finally, we’ll copy the Drupal Search API Solr Search module configuration files to the Solr home directory.
sudo cp sites/all/modules/contrib/search_api_solr/solr-conf/4.x/* /usr/share/tomcat7/solr/conf/
Defining the Solr Core
First, we’ll need to define our Solr core by editing solr.xml (the name of ‘drupal’ is arbitrary).
sudo vim /usr/share/tomcat7/solr/solr.xml
<?xml version="1.0" encoding="UTF-8" ?> <solr persistent="false"> <cores adminPath="/admin/cores"> <core name="drupal" instanceDir="drupal" /> </cores> </solr>
Next, we’ll create the Solr core directory.
sudo mkdir /usr/share/tomcat7/solr/drupal
Then, we’ll copy our base Solr configuration files to the core directory.
sudo cp -r /usr/share/tomcat7/solr/conf /usr/share/tomcat7/solr/drupal/
Finally, we can verify the Solr core is available by browsing to http://localhost:8080/solr/#/~cores/drupal:
Configuring Search API
Now that Solr is up and running, add a Solr server within Drupal: use a “Solr Service” class on localhost with port 8080 and a path of: /solr/drupal:
Next, add an index, selecting the previously created server and other settings of your choice: