/ apache

How to install Apache SOLR 4.4 on Ubuntu 12.04

EDIT: new version with SOLR 4.7 and multicore can be found here : http://www.arborisoft.com/how-to-install-multicore-apache-solr-4-7-on-debian-7/

Apache SOLR is a very fast and extremely powerful search engine which can easily be connected to your Drupal website (for example) using the Drupal module.
Its major features include powerful full-text search, hit highlighting, faceted search, near real-time indexing, dynamic clustering, database integration, rich document (e.g., Word, PDF) handling, and geospatial search.

Yeah I know it sounds great, but there is still one little thing you should now, it requires a Java web server (Tomcat, Jetty)...

Installation on Ubuntu 12.04

When I write this article, the latest version of Apache SOLR is currently 4.4, and we will install it on a Tomcat web server.
On Ubuntu 12.04, it's possible to use the command "apt-get install solr-tomcat" to install both Apache SOLR and Tomcat 6. Unfortunately, this will install SOLR in version 1.4, so we will install everything manually.

Install Tomcat 6:

apt-get update
apt-get install tomcat6 tomcat6-admin

Download and install Apache SOLR 4.4

wget http://archive.apache.org/dist/lucene/solr/4.4.0/solr-4.4.0.tgz
tar -vxf solr-4.4.0.tgz
mkdir /opt/solr
cp -r solr-4.4.0/example/solr/* /opt/solr/
cp solr-4.4.0/example/webapps/solr.war /opt/solr/
cp -r solr-4.4.0/example/lib/ext/* /var/lib/tomcat6/shared/

Edit the Apache SOLR config file:

vi /opt/solr/collection1/conf/solrconfig.xml

Change the line "dataDir" by the following:

<dataDir>${solr.data.dir:/opt/solr/data}</dataDir>

Create the directory for the data and adjust access rights:

mkdir /opt/solr/data
chown tomcat6 /opt/solr/data/

Setup new context in tomcat pointing to our Solr files:

vi /etc/tomcat6/Catalina/localhost/solr.xml

Fill in the file with the information below:

<?xml version="1.0" encoding="utf-8"?>
<Context docBase="/opt/solr/solr.war" debug="0" crossContext="true">
<Environment name="solr/home" type="java.lang.String" value="/opt/solr" override="true"/>
</Context>

Restart tomcat:

/etc/init.d/tomcat6 restart

At this point, you have everything running.
If you browse the URL "http://SERVERIPADDRESS:8080/solr/" you should see the page below:

solr44

Tomcat 6 and Apache SOLR 4.4 are now installed and Drupal can connect to the Solr core.
If you need to change the Apache SOLR configuration files (solrconfig.xml and schema.xml) for your website, they are located in “/opt/solr/collection1/conf/”.

For advanced security, if you need to restrict access to Solr to only some servers, you can edit the Tomcat configuration file: “/etc/tomcat6/context.xml”.
For example, if you want to allow only your Drupal web server (192.168.10.235 in my case), add the lines below:

<?xml version='1.0' encoding='utf-8'?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
       allow="127\.0\.0\.1,192\.168\.10\.235"/>
</Context>