ApacheSolr Configuration in Ubuntu for Drupal

NOTE:  For installing Apache Solr with Drupal on a Windows machine, pls use following link for the setup http://drupal.org/node/532584; instead of the instructions below. Also see the comments on this link, if you face any issues.

Installing Tomcat
sudo apt-get install tomcat7 tomcat7-admin tomcat7-common tomcat7-user tomcat7-docs tomcat7-examples

Start tomcat by typing
  sudo /etc/init.d/tomcat7 start

Security (Not required if installing on same machine)
If you are using ip-tables and installing Apache Solr on an external server,
modify or add the following line to accept the port 8080
-A INPUT -p tcp -m tcp –dport 8080 -j ACCEPT

After installation type http://localhost:8080 or http://serverip:8080 in your browser.Now you should see tomcat welcome page.

Install Solr
(Check for latest version or nightly build on http://apache.rediris.es/lucene/solr/ orhttp://people.apache.org/builds/lucene/solr/nightly)
wget http://apache.rediris.es/lucene/solr/1.4.1/apache-solr-1.4.1.tgz

unzip apache-solr-1.4.1.tgz
       tar -zxvf apache-solr-1.4.1.tgz

Linking tomcat7 with Apache Solr application

mkdir /usr/share/tomcat7/webapps

This should give you an idea on where your distribution installed tomcat7.
Attention : If your path is different do not forget to also adjust this in the next steps. whereis tomcat7

should show you tomcat7: /etc/tomcat7 /usr/share/tomcat7

copy the war file to the webapps directory

sudo cp apache-solr-1.4.1/dist/apache-solr-1.4.1.war /usr/share/tomcat7/webapps/solr.war

copy the example solr application to a new directory called solr. We will change this example solr application later on to be viable for Drupal 6

sudo cp -R apache-solr-1.4.0/example/solr/ /usr/share/tomcat7/solr/
create our config file
 sudo nano /etc/tomcat7/Catalina/localhost/solr.xml
And fill it with the following configuration :
 <Context docBase="/usr/share/tomcat7/webapps/solr.war" debug="0" privileged="true" allowLinking="true" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value="/usr/share/tomcat7/solr" override="true" />
Managing tomcat7 application
 We want to see how and/or if our Solr application is running, we can do this by using the manager application. By default you don't have access to this application so we have to modify the permissions.
     sudo nano /etc/tomcat7/tomcat-users.xml

And modify it so it more or less reflects the same information as shown here.

  <role rolename="admin"/>
  <role rolename="manager"/>
  <user username="nick" password="ateneatech" roles="admin,manager"/>
Drop Tomcat security so Solr can access /usr/share/tomcat7/solr
          sudo nano /etc/default/tomcat7
And modify it so our security is disabled. Be careful if you are running on a server which you do not control 100%!
restart our tomcat service
       sudo /etc/init.d/tomcat7 restart

surf to http://localhost:8080/manager/ and log in with your username and password from above and check if the solr instance is started. If not start and it and check wether or not you receive an error code!
If your application is started, surf to http://localhost:8080/solr/admin and you should see a nice screen!

Linking Drupal 6 with a running Apache Solr
Perform this step if you do not have apache-solr module already enabled i.e. you are adding apache-solr to your app for the first time:

I assume you have Drush installed so we continue with downloading the apachesolr module. Execute this commando in the designated website.
drush dl apachesolr

Perform following steps for all installations of apache solr:
 let's copy our schema that will customize our Apache Solr Instance so it fits the "Drupal" bill.
 sudo cp apachesolr/schema.xml /usr/share/tomcat7/solr/conf/schema.xml

 sudo cp apachesolr/solrconfig.xml /usr/share/tomcat7/solr/conf/solrconfig.xml

Tip: it might be a good idea to use symbolic links so we can easily update our modules and update our schemes if they change …you never know with open source 😉

Additional : give the folder permissions!
 sudo chown -R tomcat7:root /usr/share/tomcat7/solr/

Enable the module in the modules list and go to the config screen fill in the next parameters:

Host name of your Solr server, e.g. localhost or IP Address or example.com
Solr host name: localhost

Port on which the Solr server listens. Tomcat is 8080 by default.
Solr port: 8080

Path that identifies the Solr request handler to be used.
Solr path: solr

On saving these settings, message “Your site has contacted Apache Solr” will be displayed.
You can now start indexing the existing content on your site using cron and check the amount of indexing done at “admin/settings/apachesolr/index”


What you think ? Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s