Skip to content

Instantly share code, notes, and snippets.

@patrickocoffeyo
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickocoffeyo/2efbbfe23712ea26ff61 to your computer and use it in GitHub Desktop.
Save patrickocoffeyo/2efbbfe23712ea26ff61 to your computer and use it in GitHub Desktop.
Install Solr for Drupal
#!/usr/bin/env bash
function set_message() {
echo "### ### ### ###" >&2
echo "### $1" >&2
echo "### ### ### ###" >&2
echo " " >&2
}
# Installs and configures Tomcat.
function tomcat_install() {
set_message "Install and Configure Tomcat"
sudo apt-get update
sudo apt-get install openjdk-7-jre tomcat7 tomcat7-admin curl -y
sudo service tomcat7 stop
sudo rm /var/lib/tomcat7/conf/tomcat-users.xml
sudo touch /var/lib/tomcat7/conf/tomcat-users.xml
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><tomcat-users><role rolename=\"manager-gui\"/><role rolename=\"admin-gui\"/><user username=\"drupal\" password=\"InsertPasswordHere\" roles=\"manager-gui,admin-gui\"/></tomcat-users>" >> /var/lib/tomcat7/conf/tomcat-users.xml
sudo chown -R tomcat7:tomcat7 /var/lib/tomcat7
sudo service tomcat7 start
}
function solr_dl() {
set_message "Download and unpack apachesolr in /tmp/solr."
mkdir /tmp/solr
cd /tmp/solr
curl -s http://archive.apache.org/dist/lucene/solr/4.9.1/solr-4.9.1.tgz -o solr-4.9.1.tgz
tar xf solr-4.9.1.tgz
set_message "Download and unpack Drupal apachesolr module."
curl -s http://ftp.drupal.org/files/projects/apachesolr-7.x-1.7.tar.gz -o apachesolr-7.x-1.7.tar.gz
tar xf apachesolr-7.x-1.7.tar.gz
}
function solr_install() {
set_message "Install solr."
sudo cp /tmp/solr/solr-4.9.1/example/lib/ext/* /usr/share/tomcat7/lib/
sudo cp /tmp/solr/solr-4.9.1/dist/solr-4.9.1.war /var/lib/tomcat7/webapps/solr.war
sudo mkdir -p /var/lib/tomcat7/solr
sudo cp -r /tmp/solr/solr-4.9.1/example/solr/collection1/conf /var/lib/tomcat7/solr/
sudo rsync -av /tmp/solr/apachesolr/solr-conf/solr-4.x/ /var/lib/tomcat7/solr/conf/
sudo echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><solr persistent=\"false\"><cores adminPath=\"/admin/cores\"><core name=\"drupal\" instanceDir=\"drupal\" /></cores></solr>" >> /var/lib/tomcat7/solr/solr.xml
sudo mkdir -p /var/lib/tomcat7/solr/drupal/
sudo cp -r /var/lib/tomcat7/solr/conf /var/lib/tomcat7/solr/drupal/
sudo chown -R tomcat7:tomcat7 /var/lib/tomcat7/solr
}
tomcat_install
solr_dl
solr_install
sudo service tomcat7 restart
sudo service apache2 restart
@patrickocoffeyo
Copy link
Author

Use

  • Add this script to a file, and make the file executable (sudo chmod +x thisscript.sh)
  • Run the script (./thisscript.sh)
  • Visit http://mylocalhost:8080/solr, and ensure the apachesolr page appears.
  • Username for apachesolr is drupal, password is InsertPasswordHere. As indicated, you should change it.
  • Solr core name is drupal, so the solr URL from Drupal's perspective should be http://localhost:8080/solr/drupal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment