How to set up and use Apache Solr in php

How to set up and use Apache Solr in php
Posted by Drupixels

Apache Solr is an open source search platform that allows running search queries faster. It's quite popular because of its performance and ability to easily integrate with systems such as Drupal. It stores data in a way that is very fast for queries required by faceted search. It also provides full-text searches.

Here we will be learning to install and configure Apache Solr in ubuntu 12.04. Download Apache Solr from For our case we will be using Apache Solr 4.4.0 Other things we need

  • SolrClient
  • Jetty or Tomcat to run jar file which will indexes data and sends queries to XML files created by Solr and return data. We will by using jetty in our case.

We will be using PECL solr extension for SolrPhpClient, for indexing solr data through its class & methods. In case you have not install PECL, you can do that by typing below command in your terminal sudo apt-get install php-pear You can install solr PECL extension by using the following command in your terminal. sudo pear install pecl/solr sudo pecl install -n solr sudo service apache2 restart For jetty, it can installed by using following command in your terminal sudo apt-get install jetty Once you have downloaded apache solr you need to put that in your www directory in case of LAMP and htdocs in you are using XAMPP for linux. After downloading solr, run start.jar by navigating to location SOLR-DIRECTORY/example/. Command to run jar file is same as its for any jar file i.e. java -jar start.jar. Once you have run start.jar, you can check if apache solr is running or not by access the url http://localhost:8983/solr/. By default solr uses 8983 port, so 8983 indicates port in the url. Now go to the solr directory that you have. Structure for it will like below

Apache solr structure

It is example directory which we will use mostly for our work purpose. In example directory, there is solr directory, which holds our various collections and indexed data related to that collection.