Last Updated: February 25, 2016
· polzme

How to install and use Apache Solr 4.6.1 with Drupal 7

Hi there,

At Trasys, I'm currently working on a project involving Solr.
I had no skills in Solr and I asked for help around and I'm now writing a tutorial to help beginners who wants to install Solr without Tomcat on their machine.
It's a way for me to thanks the community and a good reminder for the next time ;-)


First thing first, download Solr, use the latest version at the time of writing this tip: 4.6.1

wget -P /opt/ http://apache.belnet.be/lucene/solr/4.6.1/solr-4.6.1.tgz

Installation on the server

Uncompress the archive

cd /opt
tar -xzvf solr-4.6.1.tgz

Create a symlink

ln -s /opt/solr-4.6.1/example /opt/solr

Install a startup script

This script is for Debian 7, thanks to Weber Macedo.

By default, this script will start a multicore installation of Solr, this is the best setup.

To install it, copy the content of the link in a new file and place it in /etc/init.d/solr or do:

wget https://gist.github.com/Polzme/7367523/raw/9ccf8b040b70eca214497dc6ee2b23e9abb0b8ef/solr -O /etc/init.d/solr

Don't forget to set the file executable:

chmod +x /etc/init.d/solr

Copy the necessary files from your Drupal installation to Solr

To work with Solr, you have options. Either you work with the apachesolr module or with search API and Search API Solr.

These module provides a couple of preconfigured Solr files that you need in order to get it working properly with Drupal.
We'll use the config from the Search API Solr module, they seems to be more up to date.
In my case, the Drupal site is installed in /home/staging/public_html/.

cp -ar /home/staging/public_html/sites/all/modules/search_api_solr/solr-conf/4.x/* /opt/solr/multicore/core0/conf

If you're using Search API Solr <= version 7.x-1.3, you'll need to manually edit the file solrconfig.xml and remove three lines.


If you carefully look through the file, you'll see that these directives are in double, so that's why Solr might cause problems.

Start the Solr service

You can start it manually or using the script provided before.

To start it manually:

java -Dsolr.solr.home=multicore -jar start.jar

To start it using the service:

service solr start


/etc/init.d/solr start

The good thing using the service is that you can add it to your configuration so it's started automatically upon reboot:

update-rc.d solr defaults

To check if the service is started, you can run:

service solr status

It should returns:

[ ok ] solr is running.

Now that Solr is running, you should be able to reach the Solr dashboard at : http://localhost:8983/solr


If not, check the file permission and the previous steps, maybe you forgot something.

Also, you need to have at least Java 1.6 to get Solr working properly.

Protect your Solr dashboard

There are two ways to protect your Solr dashboard. The first one is to tweak some files from Solr and add a login/password protection, but this is rather complicated and boring, because on each update of Solr, you have to edit these files manually.

The second one is to use iptables to block external connections to port 8983.

I like to K.I.S.S. things so I'll explain how to use iptables:

iptables -A INPUT -p tcp -s localhost --dport 8983 -j ACCEPT
iptables -A INPUT -p tcp --dport 8983 -j DROP

The first command tells iptables, " accept all connections from localhost on port 8983 ", and the second tells iptables, " drop all traffic to port 8983 "—since iptables obeys rules in order from top to bottom, localhost traffic is let through, while other traffic is denied. (source: Jeff Gerling)

To save these rules permanently (so they'll persist after a reboot) on Debian (documentation), make sure you save the firewall configuration.

There are many ways to do it, the easiest is to do:

iptables-save > /etc/iptables.up.rules

Don't forget to review the file manually, just in case.

Drupal configuration

Once Solr is setup, you should be able to connect to Solr in Drupal.


You can now enjoy the Solr integration in your site !

Apache Solr upgrade

Here's the procedure for upgrading from Apache Solr 4.6.0 to 4.6.1:

/etc/init.d/solr stop
wget -P /opt/ http://apache.belnet.be/lucene/solr/4.6.1/solr-4.6.1.tgz
cd /opt
tar -xzvf solr-4.6.1.tgz
cp -ar /opt/solr/multicore/core0 /opt/solr-4.6.1/example/multicore/
rm /opt/solr
ln -s /opt/solr-4.6.1/example /opt/solr
/etc/init.d/solr start

Get more help ?

IRC: #drupal-apachesolr on Freenode

Special thanks to Weber Macedo for the explanations and the hangouts about this !

5 Responses
Add your response


See, after writing it seems much simpler ;)

  • Mac_Weber
over 1 year ago ·

Yeah yeah... but still, for a newcomer, it's not that easy !

over 1 year ago ·

Merci pour les expli.
ça ne semble pas trop compliqué.
Faut (aussi) que j'essaye ça !

over 1 year ago ·

Appreciate the post! However, put a date on your post/blog/template. This information could be obsolete within months. Second, in regards to the Drupal configuration, please provide page information.

over 1 year ago ·

This is a great write up. For those who need to have more than one index on the same Solr server (perhaps you have more than one site on the server) you place the config files from searchapisolr into /opt/solr/multicore/core1/conf/ and configure the Solr server URL (see section "Drupal configuration" of above article) to point to "http://localhost:8983/solr/core1". Of course you do this in the admin settings of your second site.

over 1 year ago ·