While there are several ways to install Tomcat 6 and Apache Solr, we will use the repository version to gain the benefit of automatic updates.
Tomcat6 as Servlet container
sudo apt-get install tomcat6
sudo apt-get install tomcat6-admin
Apache Solr Search Server
sudo apt-get install solr-tomcat
In the default Tomcat installation, no privileges are created for the Tomcat Manager, so in order to make use of the Tomcat Manager GUI, we still have to create the proper role and a corresponding user.
We’ll edit it with Vim:
sudo vim etc/tomcat6/tomcat-users.xml
<user username="tomcat" password="tomcat" roles="manager-gui"/>
sudo service tomcat6 restart
Now we can start the manager at http://localhost:8080/manager/html. At this point, you could also deploy Java applets, but for our use case, the manager simply provides an overview of our Solr installations.
In order to use Solr with Drupal, we still need to make some adjustments to our Solr configuration.
We’ll start by creating a new directory in the file-system:
We’ll use Vim to create a new file (
sudo vim solr_cocomore_drupal_demo.xml) with the following content:
<Context path="/solr" docBase="/usr/share/solr" debug="0" privileged="true" allowLinking="true" crossContext="true">
<!-- make symlinks work in Tomcat -->
<Resources className="org.apache.naming.resources.FileDirContext" allowLinking="true" />
<Environment name="solr/home" type="java.lang.String" value="/opt/solr-tomcat/solr_cocomore_drupal_demo/" override="true" />
And we need another file (
sudo vim solr.xml), containing the following code:
<solr persistent="false" sharedLib="lib">
<core name="cocomore_drupal_demo" instanceDir="cocomore_drupal_demo">
<property name="dataDir" value="cocomore_drupal_demo/data" />
Next we need to create a sub-directory…
sudo mkdir /opt/solr-tomcat/solr_cocomore_drupal_demo/cocomore_drupal_demo
Now we copy the current standard Solr configuration files
cp -R /etc/solr/conf /opt/solr-tomcat/solr_cocomore_drupal_demo/cocomore_drupal_demo/conf
The following files must be present in the conf directory for Apache Solr to function:
The files marked in red will be replaced with those included in the ApacheSolr Drupal module.
Now we need to tell Tomcat where our Solr configuration can be found. We will create a symlink for this purpose:
sudo ln -s /opt/solr-tomcat/solr_cocomore_drupal_demo/solr_cocomore_drupal_demo.xml
Important: Set correct privileges!
chmod -R 775 /opt/solr-tomcat/solr_cocomore_drupal_demo/
chown -R root:tomcat6 /opt/solr-tomcat/solr_cocomore_drupal_demo/
Now, when we visit http://localhost:8080/manager/html, we should see our Solr installation (solr_cocomore_drupal_demo).
Before we can activate the Apache Solr Search module, we must first install the SolrPhpClient in the ApacheSolr module’s path, ideally with:
svn checkout -r22 http://solr-php-client.googlecode.com/svn/trunk/ SolrPhpClient
Note: If you do not have SVN installed, you can download the SolrPhpClient from a variety of sources. See the readme file included with the ApacheSolr module for further information.
Now we should activate the following modules:
Since the default settings should match the module, a connection can already be made to Solr. However, we do not want to use the default Solr index, but our own core, so we have some adjustments to make.
In the “Advanced configuration” fieldset: we should now set Apache Solr Search as the default (“Enabled”).
In the “Search index” tab, we can now see how many documents are in the index. Of course we don’t have any yet. We can also see the number of items to be sent for indexing. Content is only indexed during Cron runs. So let’s run Cron!
After Cron has run, we should see that there are no items left to send and that documents have been indexed. Please note: There is a delay time after adding new content before it is indexed. In this example, the delay is set to two minutes.
In the “Search fields” tab, we can specify index “weights” for different fields. Higher weight values for a field give it a greater importance in the search results (not to be confused with “weight” in the context of menus or taxonomies where a higher value makes an item appear lower, i.e. “sink”).