How to install Apache SOLR 3.6 on Debian 7 or Ubuntu 12.04

I already explained how to install Apache SOLR 4 here and here, but some hosting companies keep using SOLR 3.6 (Acquia for example), so let's explain how to install this version on Debian 7 or Ubuntu 12.04.

Installation

Install Tomcat 6:

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

Download SOLR 3.6 and extract it:

wget http://archive.apache.org/dist/lucene/solr/3.6.0/apache-solr-3.6.0.tgz
tar -vxf apache-solr-3.6.0.tgz

Now, copy all needed files from the extracted archive:

cd apache-solr-3.6.0
cp dist/apache-solr-3.6.0.war /var/lib/tomcat6/webapps/
mv /var/lib/tomcat6/webapps/apache-solr-3.6.0.war /var/lib/tomcat6/webapps/solr.war
cp -r example/solr/ /var/lib/tomcat6/

Create solr.xml context file:

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

With the content below:

<Context docBase="/var/lib/tomcat6/webapps/solr.war" debug="0" reloadable="true" >
<Environment name="solr/home" type="java.lang.String" value="/var/lib/tomcat6/solr" override="true" />
</Context>

Change dataDir settings in /var/lib/tomcat6/solr/conf/solrconfig.xml by:

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

Create needed directories and restart Tomcat:

chown -R tomcat6 /var/lib/tomcat6/
chown tomcat6 /etc/tomcat6/Catalina/localhost/solr.xml
mkdir /solr
mkdir /solr/data
chown -R tomcat6 /solr
/etc/init.d/tomcat6 restart

You now have Apache SOLR 3.6 accessible at : "http://SERVERIPADDRESS:8080/solr/"

Conf files are located in : /var/lib/tomcat6/solr/conf
Data are located in : /solr/data