Skip directly to content

Drupal 7 & Apache Solr in 5 minutes

rteijeiro's picture
on Fri, 11/30/2012 - 20:00

In this post I will explain how you can configure Apache Tomcat, Apache Solr and Drupal 7 in about 5 minutes, taking into account that you have Drupal 7 installed in a Linux based server.

The first step is to install the Tomcat server if you have not already installed it:

aptitude install tomcat6 tomcat6-admin tomcat6-common tomcat6-user

Let's start the server and verify that works:

/etc/init.d/tomcat6 start

Next step is to download the Apache Solr Search Integration module for Drupal 7:

drush dl apachesolr

Now we can install Solr following the Apache Solr module README.txt. As it suggests we shouldn't use the default Ubuntu/Debian package of Apache Solr (solr-tomcat). We must download the latest supported version of Solr from the official site. The latest Solr version supported by the apachesolr drupal module is 3.6.1 so we must download this version not the version 4.0:

wget http://www.eu.apache.org/dist/lucene/solr/3.6.1/apache-solr-3.6.1.tgz

Uncompress the tarball in a safe place, for example /opt or /usr/share

tar xvzf apache-solr-3.6.1.tgz

The Solr package comes with an example application that fits well for development and testing purposes. We first should make a backup of the configuration files on the examples folder:

mv /opt/apache-solr-3.6.1/example/solr/conf/protwords.txt protwords.bak

mv /opt/apache-solr-3.6.1/example/solr/conf/schema.xml schema.bak

mv /opt/apache-solr-3.6.1/example/solr/conf/solrconfig.xml solrconfig.bak
 
Next step is to copy the configuration files that come with the Apache Solr drupal module or the integration will not work correctly. Copy the configuration files of your Solr version from the apachesolr module folder to the solr examples folder:
cp apachesolr/solr-conf/solr-3.x/* /opt/apache-solr-3.6.1/example/solr/conf/

Now we can test our Solr server starting the application from the examples folder:

cd /opt/apache-solr-3.6.1/example

java -jar start.jar

And now we should see our server running correctly from the following url:

http://yoursite.com:8983/solr/

It's time to enable the Apache Solr Framework and Apache Solr Search modules:

drush en apachesolr apachesolr_search

Verify that Drupal can connect with the Solr server from the following url:

admin/config/search/apachesolr

Try to run cron in order to verify that Solr is indexing your Drupal content correctly:

drush cron

Now you have a Solr search features on your Drupal 7. The next step is to enable Faceted Search but that will be content for another blog post ;)

Comments

Arcane's picture

Line

aptitude install tomcat6 tomcat6-admin tomcat6-common tomcat6-users

should be

aptitude install tomcat6 tomcat6-admin tomcat6-common tomcat6-user

 

rteijeiro's picture

Thank you. I have corrected the typo ;)

Arcane's picture

1. First command should be:
aptitude install tomcat6 tomcat6-admin tomcat6-common tomcat6-user

2. Resolves classes not found error message from java. Need to start jar while being in the correct directory

To start apachesolr:
cd /opt/apache-solr-3.6.1/example
java -jar start.jar

rteijeiro's picture

Thank you. I have updated the post ;)

Ricardo Amaro's picture

By starting with:

java -jar start.jar

you are starting  Jetty, therefore no need for tomcat ;)

More info here:

http://wiki.apache.org/solr/SolrJetty

 

Thank you for your straight forward tutorial.

 

rteijeiro's picture

Thank you for the info. I didn't know that the example also starts Jetty :)

Robert's picture

Since Solr 4 has been relased as stable it would be great if you could also post something on how to set this up for Drupal 7.

 

 

 

rteijeiro's picture

Hi Robert. I hope the apachesolr or the search_api_solr modules will support Solr 4 soon and I will try them ;)

Kind regards.

yugongtian's picture

Hi

I have setup ok  for the drupal solr . In my sever I have nutch, the solr search nutch data result display ok .

But drupal search result.... just show only drupal site content.

I had try groups.drupal.org/node/271533  the send box project but ......no effict .

Any helps ?

Thanks.

rteijeiro's picture

Hi, have you installed and configured this?

http://drupal.org/sandbox/cilefen/1858412

Try to review the logs and the apache solr index in order to obtain more information.

Kind regards.

yugongtian's picture

Thnaks.

I was try that sand box project.

It just edit nutch-site.xml file . and two fiel .all in nutch patch .

The same version 7.x1.1 -_-

So hard to me . the result not show.

only drupal core node can by search .

I thinks use drupal to solr nutch mabe not a good way.

I just want to caret a search web site .like google .small web site.only crawl less then 10 sites.

Some korean lauguage.

I was try nutch , yioop .so many problem aHA.

Thanks.  I will looking for new project.

Travis's picture

This really helped me out, thanks a bunch!

Mohamed's picture

Thank you so much for making it so simple. I tested it with Apache Solr 4.3 and it seems to be working, at least this is what I see on the Status report page from within Drupal. I have one question though. 

I found out that Apache solr shuts down whenever I close the terminal. How can you make it run n the background permenantly? 

Thanks again!

rteijeiro's picture

Hi, sorry for the late response. A lot of Spam comments :(

You must run Apache Solr as a service. Take a look at this link:

http://stackoverflow.com/questions/2150767/how-to-start-solr-automatically

k91s71n4's picture

pues buscando como poner solr en mi web voy y me encuentro contigo.

 

soy tu peor pesadilla!

Shaun Dychko's picture

From what I can tell, these instructions work only because openjdk-6-jre-headless is installed as a dependency for tomcat6. Jetty, which is included with the Solr download is used instead by the time these instructions are completed. You can replace the line

<code>

aptitude install tomcat6 tomcat6-admin tomcat6-common tomcat6-use

</code>

with

<code>

aptitude install openjdk-6-jre-headless

</code>

and achieve the same result.

Post new comment