Comments

humPhin’s picture

because of a new account, unable to add a child page so adding this comment :)

I used a combination of resources to get this setup working:

references: https://www.digitalocean.com/community/tutorials/how-to-install-apache-t...
https://www.lullabot.com/articles/installing-solr-for-use-with-drupal

SETUP AND INSTALL TOMCAT
1) sudo apt-get update
2) sudo apt-get install default-jdk
3) sudo groupadd tomcat
4) sudo useradd -s /bin/false -g tomcat -d /usr/local/tomcat tomcat
5) cd /tmp
6) curl -O http://www.namesdir.com/mirrors/apache/tomcat/tomcat-8/v8.5.13/bin/apache-tomcat-8.5.13.tar.gz
7) sudo mkdir /usr/local/tomcat
8) sudo tar xzvf apache-tomcat-8*tar.gz -C /usr/local/tomcat --strip-components=1
9) cd /usr/local/tomcat
10) sudo chgrp -R tomcat /usr/local/tomcat
11) sudo chmod -R g+r conf
12) sudo chmod g+x conf
13) sudo chown -R tomcat webapps/ work/ temp/ logs/
14) sudo nano /etc/systemd/system/tomcat.service
add the following in the above file:

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
Environment=CATALINA_PID=/usr/local/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/usr/local/tomcat
Environment=CATALINA_BASE=/usr/local/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

15) sudo systemctl daemon-reload
16) sudo systemctl start tomcat
17) sudo systemctl status tomcat
18) sudo ufw allow 8080 (if your firewall is enabled)
19) sudo systemctl enable tomcat (enable the service file so Tomcat will start automatically on system boot)

CONFIGURE TOMCAT WEB MANAGEMENT (Optional)
20) sudo nano /usr/local/tomcat/conf/tomcat-users.xml
place the following in the above file:

<tomcat-users . . .>
    <user username="admin" password="anewpassword" roles="manager-gui,admin-gui"/>
</tomcat-users>

21) sudo nano /usr/local/tomcat/webapps/manager/META-INF/context.xml
comment out as below:

<Context antiResourceLocking="false" privileged="true" >
  <!--<Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />-->
</Context>

22) sudo nano /usr/local/tomcat/webapps/host-manager/META-INF/context.xml
comment out as below:

<Context antiResourceLocking="false" privileged="true" >
  <!--<Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />-->
</Context>

23) sudo systemctl restart tomcat

at this point, you should be able to access the tomcat web interface at http://server_domain_or_IP:8080

INSTALLING SOLR
24) cd /usr/local/src
25) sudo wget http://archive.apache.org/dist/lucene/solr/4.6.0/solr-4.6.0.tgz
26) sudo tar -zxf solr-4.6.0.tgz
27) sudo cp solr-4.6.0/dist/solrj-lib/* /usr/local/tomcat/lib/
28) sudo cp solr-4.6.0/example/resources/log4j.properties /usr/local/tomcat/conf/
29) sudo cp solr-4.6.0/dist/solr-4.6.0.war /usr/local/tomcat/webapps/solr.war
30) sudo mkdir -p /usr/local/tomcat/conf/Catalina/localhost
31) sudo nano /usr/local/tomcat/conf/Catalina/localhost/solr.xml
add the following to the above file:

<Context docBase="/usr/local/tomcat/webapps/solr.war" debug="0" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value="/usr/local/tomcat/solr" override="true" />
</Context>

32) sudo mkdir -p /usr/local/tomcat/solr
33) sudo cp -r solr-4.6.0/example/solr/collection1/conf /usr/local/tomcat/solr/
34) download and install https://drupal.org/project/apachesolr
35) cd into your drupal installation sites/all/modules directory
36) sudo rsync -av apachesolr/solr-conf/solr-4.x/ /usr/local/tomcat/solr/conf/
37) sudo nano /usr/local/tomcat/solr/solr.xml
add the following to the above file:

<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
  <cores adminPath="/admin/cores">
    <core name="drupal" instanceDir="drupal" />
  </cores>
</solr>

38) sudo mkdir /usr/local/tomcat/solr/drupal
39) sudo cp -r /usr/local/tomcat/solr/conf /usr/local/tomcat/solr/drupal/
40) sudo chown -R tomcat:tomcat /usr/local/tomcat
41) sudo systemctl restart tomcat

at this point, the solr core admin interface should be available at http://server_domain_or_IP:8080/solr/#/drupal
URL to use in Drupal's Apache Solr configuration is http://localhost:8080/solr/drupal.

hope this helps.

Andy_D’s picture

This guide is brilliant and got me up and running in no time. Thank you so much for submitting this humPhin

I used Tomcat 8.5.12 and Solr 4.6.1 - you just need to change download locations as applicable.

curl -O http://apache.mirrors.nublue.co.uk/tomcat/tomcat-8/v8.5.12/bin/apache-tomcat-8.5.12.tar.gz
and
sudo wget http://archive.apache.org/dist/lucene/solr/4.6.1/solr-4.6.1.tgz

Also step 33 needs a sudo!
33) sudo cp -r solr-4.6.0/example/solr/collection1/conf /usr/local/tomcat/solr/

humPhin’s picture

I'm glad it helped! thanks for pointing out step #33, fixed :)

Andy_D’s picture

It's also worth noting that when you add the server and an index in Drupal then try to index all items it will probably fail with the following error or something similar:

SearchApiException: Could not index items since important pending server tasks could not be performed. in search_api_index_specific_items() (line 1622 of /var/www/site/docroot/sites/all/modules/contrib/search_api/search_api.module).

This is because the Solr server needs to create the data directory first. Just reindex again and it should work second time around.

Tart0’s picture

Thanks both of you for your help, it should be into the official doc haha

Also, step 6 is a dead link, you can replace the current path with http://apache.osuosl.org/tomcat/tomcat-8/v8.5.32/bin/apache-tomcat-8.5.3... which is availlable :)