Solr is a well-known robust open source search platform that is been brought to us by Apache Lucene. It is Java-based and runs within a servlet container (Tomcat / Jetty) as a stand-alone search server. Solr core constitutes of Lucene Java search library that is primarily responsible to perform full-text index and search operations. Additionally, Solr core consists of REST-like HTML / XML and JSON APIs that makes Solr compatible with any programming and/or scripting language. We can even scale our Solr and its external configuration without writing a single line of Java code. Since, Solr believes in extensive plugin architecture, it allows us to even customize it as-and-when required.
In this article, we will learn how to install Apache Solr specific to Drupal in LINUX environment (CentOS in our case). We want to install Solr 4.6.0 on CentOS and intend it to run on Tomcat 7.
So let us get started !
Install Java:
Since we want our Solr to run on Tomcat (Java based applications), the primary prerequisite would be to install Java. Since the Java installation process differs based on LINUX distribution and Java flavors we intent to use, though any Java flavor should work here in this case. Here in our example, we will use OpenJDK implementation of Java 7. If you already have Java installed and is in place, you may ignore this step.
Please ensure that you have the full Java Development Kit (JDK) installed. Just installing Java Runtime Environment (JRE) is not sufficient.
In order to install our JDK, we run the following command:
Install Tomcat:
By now, we have JDK package installed. Some LINUX distributions come up with Tomcat package, however it is always recommended to install the latest version of it to ensure latest security and bug fixes are in place. So, in order to install Tomcat, we follow the below steps:
- We download the latest binary of Tomcat from http://tomcat.apache.org/download-70.cgi to /usr/local/ on our server.
- Unpack the Tomcat binary file to /usr/local/tomcat. To do so, we run the following command:
- Since Tomcat listens to port 8080 (by default - which is a common port used by a few other services), there is a possibility to face conflicts due to this. Though this step is optional, let us force tomcat to listen at port 8983 instead of the default one so as to avoid such conflicts. We run the following command:
- Now it is time to test our Tomcat installation. To do so, we run the following command that executes the startup script:
Install Solr:
By now, we have our necessary components in place and are up and running. It’s time to install Solr. To do so, we follow the below steps.
- Download the stable version of Solr-4.6.0 from http://www.apache.org/dyn/closer.cgi/lucene/solr/4.6.0 to any of the locations in the server and unpack the downloaded file using
- Copy all Solr specific Java libraries to Tomcat library using:
- Copy log4j (configuration file) shipped by Solr to the Tomcat configuration folder using:
- Copy solr-4.6.0.war to Tomcat webapps directory and rename it as solr.war.
- Create solr.xml (Context file) at /usr/local/tomcat/conf/Catalina/localhost/ and populate it with the following content:
Solr Index:
As you must be aware of that Solr is capable enough to provide multiple search indexes or cores, each possessing their own configuration file; hence these cores can be configured independently. We will now following the below steps so as to create a core named as drupalproj which will be used exclusively for our Drupal application.
- Create a Solr directory and copy the example configuration as demonstrated below:
- Download the latest and stable version of apachesolr Drupal contributed module from https://drupal.org/project/apachesolr and unpack to a location in the server.
- Now copy the Solr specific configuration files from the apachesolr Drupal module to the Solr configuration directory as shown below:
- Then create the definition file solr.xml for the Solr core at /usr/local/tomcat/solr/ and populate the below content:
- Create Drupal specific Solr core directory and populate with the example Solr configuration files to it as demonstrated below:
- Stop and start Tomcat by running shutdown and startup scripts, as shown below:
Our new Solr core admin panel would be available at http://localhost:8983/solr/#/drupal (http://localhost:8080/solr/#/drupal in case you didn’t alter the default port). You are now ready to use Drupal’s Apache Solr configuration and will be found at http://localhost:8983/solr/drupal (Replace 8983 with 8080 in case tomcat listens to the default port).
Conclusion:
In this article learnt how to install Solr and necessary components that are specific to Drupal. Comments and suggestions along with queries are most welcomed.
Stay tuned for upcoming blogs that might interest you!!!