Java 8, Tomcat 7, and Solr 4.3 on Yosemite for Drupal Development

I recently did a clean install of Yosemite on my local work station. I then installed Solr to run in Tomcat because I wanted to learn more about Tomcat. I looked at several posts to help me get my configuration the way I liked it. References are at the end of this document.

I wanted to install Solr and Tomcat with Homebrew, but I couldn't get Solr to be found by Tomcat with Homebrew installations. Additionally, Homebrew was stuck looking for an earlier version of Java than the one I upgraded my system to. So it was time to work outside of Homebrew, a somewhat but not too scary proposition.

1. Upgrade to Java 8

Click on over to Oracle.com and download the latest Java 8 JDK for MAC OS X x64 (jdk-8u25-macosx-x64.dmg as of this writing). Open the .dmg file and run the installer which copies the Java VM and Runtime into

/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk

Add this line to your ~/.bash_profile to tell your system to recognize the upgraded java.

export set JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

After you source ~/.bash_profile, java -version should respond with:

java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

2. Install Tomcat

Next, go to Apache.org to download the Tomcat distribution. I'm using Tomcat 7.0.57 for now (version number as of this writing) but I will update this post if I switch to Tomcat 8. Download the Binary Distributions - Core tar.gz file. Once the tar.gz file is downloaded, run these steps:

cd ~/Downloads/ 
tar -zxvf ./apache-tomcat-7.0.57.tar.gz
mv ~/Downloads/apache-tomcat-7.0.57/ /usr/local/tomcat

I keep the attributes of my /usr/local as <my-name>:admin. I don't remember if I changed that or if Homebrew did. In case your /usr/local is owned by root:admin, you'll need to use sudo when working in your /usr/local directory.

You'll want to change the Connector for Tomcat from port 8080 (its default) to something else, like port 8983.

sed -i '' 's/8080/8983/g' /usr/local/tomcat/conf/server.xml

The empty quotation marks are not a typo. On OS X, which is a BSD sed, the suffix is mandatory.

At this point you can start and stop tomcat with command strings like:

/usr/local/tomcat/bin/startup.sh

and

/usr/local/tomcat/bin/shutdown.sh

but I like to use Activata's Tomcat Controller, a freeware app whose application icon can be saved in the dock and in which you can save preferences.

Set up Tomcat Controller's preferences like so:

Now, when you click View in Tomcat Controller, Tomcat's default home page should open in your browser:

While we're here, let's set up access to the manager-gui which we will want to use later by editing /usr/local/tomcat/conf/tomcat-users.xml. Change the tomcat-users to:

<tomcat-users>
  <role rolename="manager-gui"/>
  <user username="tomcat" password="tomcat" roles="manager-gui"/>
</tomcat-users>

3. Install Apache Solr

I'm using Solr version 4.3.0 because the Drupal apachesolr module references that version directly (See sites/all/modules/contrib/apachesolr/solr-conf/solr-4.x/solrconfig.xml line 23).

mkdir -p /usr/local/src
cd /usr/local/src

Yosemite doesn't come with wget pre-installed, at least my Yosemite didn't. If you find that to be your case, you can use either Homebrew to install wget or go to this post:

http://coolestguidesontheplanet.com/install-and-configure-wget-on-os-x/

and follow its instructions. Anyway, once wget is installed:

cd /usr/local/src
wget http://archive.apache.org/dist/lucene/solr/4.3.0/solr-4.3.0.tgz 
tar xvf solr-4.3.0.tgz 

From /usr/local/src we'll copy Solr configuration files into Tomcat. 

yes | cp -a solr-4.3.0/dist/solrj-lib/* /usr/local/tomcat/lib 
yes | cp -a solr-4.3.0/example/resources/log4j.properties /usr/local/tomcat/conf 
yes | cp -a solr-4.3.0/dist/solr-4.3.0.war /usr/local/tomcat/webapps/solr.war 

Create the Apache Solr context file:

mkdir -p /usr/local/tomcat/conf/Catalina/localhost/ 
vi /usr/local/tomcat/conf/Catalina/localhost/solr.xml 

and paste in the following: 

<Context docBase="/usr/local/tomcat/webapps/solr.war" debug="0" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value="/usr/local/tomcat/solr" override="true" />
</Context>

4. Install Apache Solr

Download the module:

cd /usr/local/src 
wget http://ftp.drupal.org/files/projects/apachesolr-7.x-1.7.tar.gz 
tar xvf apachesolr-7.x-1.7.tar.gz 

Setup a Solr directory and configuration in Tomcat and copy the Drupal module's configuration files into it.

mkdir -p /usr/local/tomcat/solr 
yes | cp -r solr-4.3.0/example/solr/collection1/conf /usr/local/tomcat/solr 
rsync -av apachesolr/solr-conf/solr-4.x/ /usr/local/tomcat/solr/conf 
mkdir /usr/local/tomcat/solr/drupal 
yes | cp -r /usr/local/tomcat/solr/conf /usr/local/tomcat/solr/drupal 

Create the Apache Solr Drupal settings xml in tomcat/solr. 

 

vi /usr/local/tomcat/solr/solr.xml 

Paste the following in:

<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
  <cores adminPath="/admin/cores">
    <core name="drupal" instanceDir="drupal" />
  </cores>
</solr>

And we're done. After you restart Tomcat using the Tomcat Controller, click View and you will be directed to the Tomcat Homepage in your browser. You can now click the Manager app button which is on the right side in the green area toward the top of the page. You will then be prompted with the Authentication Required pop-up. Use User Name: tomcat Password: tomcat per our earlier set up in /usr/local/tomcat/conf/tomcat-users.xml.

You will then be sent to the Tomcat Web Application Manager page. At the bottom of Applications table you will see an entry for /solr. Click /solr to launch Solr and go to the Solr Dashboard. Once you've indexed your content at admin/config/search/apachesolr in Drupal, you can find your content in Solr by selecting the drupal in the Core Selector list and executing a query in the Query tab.

References

Java 8, Tomcat 8, and RESTEasy on Mac OS X

How to install Apache Solr 4.6 with Apache Tomcat 7, for use with Drupal

Installing Tomcat 7.0.x on OS X

Install and Configure wget on OS X Yosemite 10.10 and fix SSL GNUTLS error

 

Add new comment