Apache Solr, Tomcat 6 and Drupal in Ubuntu 10.04
Solr is the popular, blazing fast open source enterprise search platform from the Apache Lucene project. Its major features include powerful full-text search, hit highlighting, faceted search, dynamic clustering, database integration, and rich document (e.g., Word, PDF) handling. Solr is highly scalable, providing distributed search and index replication, and it powers the search and navigation features of many of the world's largest internet sites.
Solr is written in Java and runs as a standalone full-text search server within a servlet container such as Tomcat. Solr uses the Lucene Java search library at its core for full-text indexing and search, and has REST-like HTTP/XML and JSON APIs that make it easy to use from virtually any programming language. Solr's powerful external configuration allows it to be tailored to almost any type of application without Java coding, and it has an extensive plugin architecture when more advanced customization is required.
To install Tomcat 6 in Ubuntu is like everything esle composed of only a few steps:
apt-get update && apt-get upgrade apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-user tomcat6-docs tomcat6-examples
If you want to be able to access the administration page, you will have to set a password:
vi /etc/tomcat6/tomcat-users.xml
Uncomment and modify the following lines (keep the admin and manager roles):
<tomcat-users> <role rolename="admin"/> <role rolename="manager"/> <user username="vlad" password="XXXXXXXX" roles="admin,manager"/> </tomcat-users>
Now let's download and "install" Solr. This is just as simple as copying the right files in the right place.
cd ~ wget http://www.motorlogy.com/apachemirror/lucene/solr/1.4.0/apache-solr-1.4.0.tgz tar -zxvf apache-solr-1.4.0.tgz cp ~/apache-solr-1.4.0/dist/apache-solr-1.4.0.war /usr/share/tomcat6/webapps/solr.war cp -R ~/apache-solr-1.4.0/example/solr/ /usr/share/tomcat6/solr/
Also create the following file:
vi /etc/tomcat6/Catalina/localhost/solr.xml
And write the following lines:
<Context docBase="/usr/share/tomcat6/webapps/solr.war" debug="0" privileged="true" allowLinking="true" crossContext="true"> <Environment name="solr/home" type="java.lang.String" value="/usr/share/tomcat6/solr" override="true" /> </Context>
If you want to have multiple instances of solr you can add them as separate cores. You will have to define them in another solr.xml file:
cp ~/apache-solr-1.4.0/example/multicore/solr.xml /usr/share/tomcat6/solr/solr.xml
This is the configuration file in which you can add as many cores as you want.
<cores adminPath="/admin/cores">
<core name="VladGh.com" instanceDir="vladgh.com" />
</cores>Now create the folders, and copy the conf folder to each of them
mkdir /usr/share/tomcat6/solr/vladgh.com mkdir /usr/share/tomcat6/solr/vladgh.com/data chown -R tomcat6:tomcat6 /usr/share/tomcat6/solr/vladgh.com/data cp -r /usr/share/tomcat6/solr/conf /usr/share/tomcat6/solr/vladgh.com/conf
In this example I created the folder vladgh.com with the folder data inside it, all owned by tomcat6 user.
Next comes the drupal part:
drush dl apachesolr svn checkout -r22 http://solr-php-client.googlecode.com/svn/trunk/ /srv/vladgh.com/sites/all/modules/apachesolr/SolrPhpClient
Here I am using Drush, but you can also simply download the project files from Drupal Modules and unzip it into your modules folder.
Then you will have to modify the schema files of solr to be used with drupal. They are located in the module folder you just downloaded.
mv /usr/share/tomcat6/solr/vladgh.com/conf/schema.xml /usr/share/tomcat6/solr/conf/schema.xml.original mv /usr/share/tomcat6/solr/vladgh.com/conf/solrconfig.xml /usr/share/tomcat6/solr/conf/solrconfig.xml.original ln -s /srv/vladgh.com/sites/all/modules/apachesolr/schema.xml /usr/share/tomcat6/solr/vladgh.com/conf/schema.xml ln -s /srv/vladgh.com/sites/all/modules/apachesolr/solrconfig.xml /usr/share/tomcat6/solr/vladgh.com/conf/solrconfig.xml
Enable the module and go to the configuration page (http://example.com/admin/settings/apachesolr/settings)
Solr Hostname: localhost
Solr Port: 8080
Solr Path: /solr/VladGh.com (the argument provided here is the name of the core used earlier, case sensitive)
/etc/init.d/tomcat6 restart
Also you can set the default behaviour in case of failure (to show core drupal results), and make this module the default search engine (Advanced Configuration -- Make Apache Solr Search the default)



