Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Install Apache Solr on Localhost

Video loading...

  • 0:00
    Install Apache Solr on Localhost with Joe Shindelar
  • 0:03
    Before we can start integrating Drupal with Apache Solr,
  • 0:08
    we need to get an instance of Apache Solr running that we can play around with.
  • 0:11
    There's two different ways we could do this,
  • 0:13
    and I'm going to cover it in two separate tutorials.
  • 0:15
    In this tutorial, I'm going to walk through how we can install Solr
  • 0:19
    on a localhost for development,
  • 0:21
    and in another tutorial, I'll walk through sort of the considerations that you want to keep in mind
  • 0:25
    when installing Solr on a production environment.
  • 0:28
    So in this tutorial, we're going to go through
  • 0:31
    the requirements for running Solr on your local environment.
  • 0:34
    And then we'll walk through downloading
  • 0:37
    the Solr example application and running it.
  • 0:40
    I'm going to be doing this on Mac OS.
  • 0:42
    However, the process should be pretty similar whatever OS you're running.
  • 0:46
    Ultimately, the requirements are we need Java in order to run Solr.
  • 0:50
    Most modern OSes already have that installed.
  • 0:53
    If you don't though, you can follow instructions online
  • 0:57
    for installing the Java JDK in order to run Solr.
  • 1:00
    Setting up Solr on your local host is a really great thing to do
  • 1:04
    if what you're ultimately doing is just practicing
  • 1:07
    or doing some development work on a site that's hosted elsewhere
  • 1:11
    and when you've got Solr hosted by another company.
  • 1:14
    A lot of Drupal hosts like Acquia and Pantheon and many of the others
  • 1:18
    include Solr hosting as part of their package.
  • 1:21
    And so your production site could just link up to their Solr instances,
  • 1:25
    but you'll still want to be able to work on things locally.
  • 1:27
    So this is how we're going to run Solr on our local machine.
  • 1:30
    There's some decent documentation available for this
  • 1:33
    on drupal.org/node/1999310.
  • 1:38
    I'll put a link to it in the notes for this tutorial.
  • 1:40
    That will be easier to get to.
  • 1:42
    And you can read through the documentation here. It talks about setting up Solr.
  • 1:45
    Some of it is a little bit out of date.
  • 1:48
    In some cases it talks about older versions of Solr.
  • 1:51
    Here we're talking about Solr 3.6.
  • 1:53
    At the time that this was recorded, Solr 5 is actually
  • 1:57
    the most current version.
  • 1:59
    However, we're going to be installing the latest version of Solr 4
  • 2:02
    because the Search API module hasn't yet been updated to work with Solr 5.
  • 2:06
    It's really recent. It just came out about a week ago.
  • 2:09
    So what we're going to need to do is ensure that we have Java 6 or higher
  • 2:13
    in order to run Solr 4x.
  • 2:17
    Then we need to download a copy of Solr to our localhost.
  • 2:20
    We'll take a look at the files that are included,
  • 2:22
    and then we'll demonstrate how you can run the example application
  • 2:26
    and start taking a look at the Solr administration interface and so forth.
  • 2:31
    So the first step is just follow the link here to download the latest version of Solr.
  • 2:36
    We can click that link.
  • 2:38
    And that takes us to a page on the apache.org,
  • 2:42
    so lucene.apache.org/solr/downloads.html.
  • 2:47
    We're actually going to go to the link here for past versions
  • 2:50
    because we do want an older version.
  • 2:52
    Like I said, Solr 5 just came out,
  • 2:55
    and you can see it's the 5.0.0 is the current release,
  • 2:58
    but Search API doesn't yet support it.
  • 3:01
    So we're going to go to the Apache archives.
  • 3:03
    And then we'll find the latest version of the 4x release cycle.
  • 3:08
    So here we've got 4.10.4.
  • 3:11
    That's the one that we're going to be using, so I'll click on that.
  • 3:13
    There's a bunch of files in here.
  • 3:15
    You can download various versions of Solr.
  • 3:18
    It's open source, so you can actually download the source code if you want to.
  • 3:21
    We don't really need that for our purposes.
  • 3:24
    We're just going to download the already compiled Java code and be able to run that.
  • 3:28
    So select this version here, the solr-4.10.4.tgz.
  • 3:33
    I'm just going to copy that link address.
  • 3:35
    What I'll do is download that file.
  • 3:38
    I'm going to switch to my terminal.
  • 3:40
    In this case, I'm going to download the Solr files
  • 3:43
    into my working directory for the site that I'm building in this tutorial.
  • 3:48
    If I list the files here, you can see I've got a directory named docroot.
  • 3:51
    Inside of docroot is our Drupal installation.
  • 3:55
    Inside of data and misc are various things
  • 3:58
    that ultimately will be bundled up and included with this tutorial.
  • 4:01
    You can download Solr wherever you want to.
  • 4:03
    You only need one copy of it on your machine,
  • 4:07
    so you can just download it into your applications folder
  • 4:10
    or user/local or whatever, wherever you normally put these things.
  • 4:14
    I'm going to go ahead and download it.
  • 4:16
    The download from the apache.org mirrors can be a little bit slow sometimes,
  • 4:20
    so I'm just going to go ahead and pause this and let it complete.
  • 4:24
    All right, once that download's complete,
  • 4:27
    I'll list the files, and you can see I've now got this 10.4.tgz.
  • 4:31
    The other one here is from an experiment I was doing earlier.
  • 4:34
    I'm going to unpack this file, so I'll use tar to unpack it.
  • 4:38
    Extract all the files.
  • 4:43
    And now I've got a directory solr-4.10.4, like so,
  • 4:49
    which contains a bunch of information about Solr,
  • 4:53
    so a README a license and so forth.
  • 4:56
    It contains a bin directory, which has executables,
  • 4:59
    a contrib directory, which contains plugins for Solr.
  • 5:02
    The part that I'm interested in is actually this example directory.
  • 5:05
    The example directory contains
  • 5:08
    an example preconfigured, precompiled version
  • 5:13
    of Solr and all of its source code into what is considered a good build for web applications.
  • 5:19
    Whenever I'm running this on my localhost just to do development work,
  • 5:23
    I always just use the example application.
  • 5:25
    You'll have to change some of the configuration,
  • 5:27
    which we'll talk about in another tutorial
  • 5:29
    where we look at how to set configuration
  • 5:32
    that is specific to Drupal in a Solr application.
  • 5:35
    But for now, let's just talk about how we can get it up and running.
  • 5:38
    Here we've got this start.jar file.
  • 5:41
    So this is a Java executable file,
  • 5:44
    and what I can do with Java at the command line
  • 5:46
    is type the command java-jar start.jar. like so,
  • 5:52
    and then run it.
  • 5:55
    And what this will do is use Java to start up
  • 5:58
    an instance of that jar file,
  • 6:00
    which is basically our Solr application.
  • 6:03
    It's got one core configured already named collection one.
  • 6:08
    That's just the default, which we'll be making use of.
  • 6:10
    This works great, again, for localhost.
  • 6:13
    You could run it in the background if you wanted to.
  • 6:15
    You could just start it in a terminal and run it as needed for your development work,
  • 6:19
    and then turn it off when you're not using it.
  • 6:21
    When you're running in a production, there's other things that you need to keep in mind—
  • 6:25
    security being one of them, performance.
  • 6:28
    There are more performant ways that we could start and run Solr.
  • 6:31
    You also want to do things like set it up so that
  • 6:33
    if the server needs to be reboot it automatically starts the Solr server for you.
  • 6:38
    But anyway, we've got it running on our localhost right now.
  • 6:42
    I can confirm this by going to my browser,
  • 6:45
    and in my browser I'm going to go to localhost,
  • 6:48
    port 8983,
  • 6:52
    which is the default port for this example Solr application,
  • 6:56
    slash Solr. [localhost:8983/solr]
  • 6:59
    Doing so allows me to view the Apache Solr web administration interface.
  • 7:04
    This confirms for me that Solr is running.
  • 7:07
    I just started it about a minute ago.
  • 7:09
    It tells me some information about how much memory it's using, etcetera.
  • 7:12
    I can go down here to my core selector, and I can see that I've got one core set up for Solr.
  • 7:17
    You can have multiple cores for different sites and so forth.
  • 7:21
    We're just going to be working with this one Solr core
  • 7:23
    for our tutorial and demonstration purposes.
  • 7:26
    So that's getting Solr running on your localhost.
  • 7:29
    In this tutorial, we took a look at the requirements for running Solr,
  • 7:33
    which really just boils down to a modern version of Java—
  • 7:37
    Java 6 at the minimum, 7 or 8, 8 being the latest release.
  • 7:42
    I haven't had any problems running it with the latest versions of Java,
  • 7:45
    so that is what I would encourage you to do.
  • 7:47
    The process for installing Java is going to vary depending on your OS.
  • 7:51
    Most OSes, though, come with Java already installed
  • 7:55
    or have easy binaries for doing so.
  • 7:57
    With Java installed, all we had to do was download the Solr source code
  • 8:02
    and the example application from the Apache website
  • 8:04
    and then extract those files.
  • 8:06
    And then we used the start.jar
  • 8:09
    in the example Solr application to start up a Solr server.
  • 8:13
    We were then able to confirm that it was running
  • 8:15
    by visiting the Solr administration UI in our browser.

Install Apache Solr on Localhost

Loading...

Solr is an application that runs on it's own, independent of Drupal. So before we can integrate our Drupal site with the Solr server we first need to install Solr and get it running. In this tutorial we'll walk through the requirements for installing Solr and then look at a quick and easy way to get it running on our localhost for development purposes. This setup is best for when you're working on a site locally, but have it hosted elsewhere and someone else is managing your Solr install for you.

The basic process is to download the Solr application, unpack it somewhere on your localhost, and then run the start.jar file that comes with the example application: java -jar start.jar. To ensure it's working you can connect to the Solr web UI on your localhost at http://localhost:8983/solr/.

Note: When using Solr with Drupal and the Search API module we currently need to use the most recent 4.x version of Solr, despite the fact that there is a 5.x version that just came out. At the time these tutorials where recorded the Search API module had not yet been updated to work with Solr >= 5.x. The general installation instructions for localhost development however are not likely to change much at all between Solr 4 and 5 so even if you're using Solr 5 this should still be relevant information.

By the end of this tutorial you should be able to run Solr on your localhost and verify that it is working.