How to Install Apache Solr for Magento Store?

Table of Content

How to Install Apache Solr for Magento Store?

How to install Apache Solr for Magento store?

Do you know how many customers your Magento store is losing just because your visitors can’t find the products they need since the search system is imperfect? Huge stores with an extensive amount of products suffer from it dramatically. Learn how to help your customers to find what they need and boost your sales by installing Apache Solr.

When a customer doesn’t know the exact product name, search of the good he wants turns into a long adventure. Grouping by categories and Improved Sorting might make the situation a little bit better, but if one doesn’t know what category a product belongs to or how its name is spelled, the search result might be inappropriate.

To solve this problem Magento offers full-text search. Starting from version 1.8.0.0 Magento Enterprise supports not only the full-text search based on MySQL (used by default), but also Apache Solr search engine. And until recent our Magento extensions Improved Layered Navigation also supports Solr, which makes it easy to use for Magento sotre owners with any level of web-literacy.

Read a complete guide to search in Magento 2

See how to optimize your Magento 2 store for voice search

What are the advantages of Apache Solr integration with Magento store?

Installation of Apache Solr for your Magento Store provides you with a number of advantages in comparison with the full-text search based on MySQL:

  • Zero results tips or results correction;
  • Suggestions;
  • Clustering;
  • Attribute weight based on attribute settings;
  • Localized characters search;
  • Word delimiter (for example, search of “spider man”, “spiderman return” or “spider-man”).

What is the essence of this installation?

Apache Solr installation consists of the following stages:

  1. Installation of Java Runtime Environment;
  2. Launch of Java application as a system service (to test it one can simply launch the application in the command line);
  3. Settings change of the full-text search in Magento Enterprise configuration.

Can I install Apache Solr by myself?

Since installation of Apache Solr is connected with the changes in the server configuration, we highly recommend you to refer to the professionals for the help (e.g. technical support service of your hosting). Before starting the installation please make a backup copy of your website and make sure you know how to restore the website from it!

How to install Apache Solr search for Magento store?

DISCLAIMER: If configured improperly Solr might have an adverse effect on server security. Carefully setup your firewall to protect Solr from possible malicious actions. Amasty takes no responsibility for any possible damages to equipment or software, downtime or any losses.

The instructions for Magento Solr setup below are suitable for Debian/Ubuntu installations, for other installations commands may vary.

Install Java.

# aptitude install openjdk-7-jre-headless

Prepare directories for Solr installations.

# mkdir /srv/solr
# useradd -d /srv/solr -s /bin/bash solr
# chown solr:solr /srv/solr/
# su - solr

Download installation package Solr 3.4 (the version is chosen in accordance with the compatibility table).

$ wget http://archive.apache.org/dist/lucene/solr/3.4.0/apache-solr-3.4.0.tgz
$ tar xf apache-solr-3.4.0.tgz

Copy Magento configurations for Solr.

$ cp -r /path/to/magento/install/lib/Apache/Solr/conf/* apache-solr-3.4.0/example/solr/conf/

Prepare auto-start script (add the contents to the file /etc/init.d/apache-solr).

#! /bin/sh
### BEGIN INIT INFO
# Provides:          apache-solr
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Apache Solr
# Description:       Apache Solr search engine
### END INIT INFO

# Author: XXXXX XXXXXXXX <[email protected]>

SOLR_DIR="/srv/solr/apache-solr-3.4.0/example"
SOLR_USER="solr"
JAVA_OPTIONS="-Xmx1024m -DSTOP.PORT=10000 -DSTOP.KEY=jetty-stop-key -jar start.jar"
LOG_FILE="/var/log/apache-solr.log"
JAVA="java"

case $1 in
        start)  
                echo "Starting Solr"
                su - $SOLR_USER -c "cd $SOLR_DIR && exec $JAVA $JAVA_OPTIONS >$LOG_FILE 2>&1 &"
                ;;
        stop)   
                echo "Stopping Solr"
                su - $SOLR_USER -c "cd $SOLR_DIR && $JAVA $JAVA_OPTIONS --stop"
                ;;
        restart)
                $0 stop
                sleep 1
                $0 start
                ;;
        *)      
                echo "Usage: $0 {start|stop|restart}" >&2
                exit 1
                ;;
esac

:

And make it executable

# chmod 755 /etc/init.d/apache-solr

Create logrotate configuration (add the contents to the file  /etc/logrotate.d/apache-solr).

/var/log/apache-solr.log {
        daily
        rotate 7
        compress
        delaycompress
        missingok
        notifempty
        create 640 solr adm
}

Initialize file logs.

# touch /var/log/apache-solr.log
# chown solr:adm /var/log/apache-solr.log
# chmod 0640 /var/log/apache-solr.log

Launch Solr and add it to auto-start.

# update-rc.d apache-solr defaults
# service apache-solr start

If everything was done correctly, Solr control panel will be available at the address http://your-site-ip:8983/solr/admin/

Settings of Magento Enterprise for working with Solr

One can find the Official Manual on Magento Solr configuration and connecting Solr to Magento here.

The installed Solr can be found at the address your-site-ip:8983. To connect it one needs to:

  • Go to Magento admin panel  System / Configuration;
  • In the group CATALOG choose Catalog / Catalog Search;
  • Choose Solr in the field Search Engine;
  • Enter your-site-ip in the Solr Server Hostname field;
  • Enter 8983 in the Solr Server Port field;
  • Enter solr in the Solr Server Path;
  • Press Test connection button. If it has changed its color to green one, Solr is connected and is ready for use;
  • Save the changes (press Save Config button).

If required, update the indices at System / Index Management.

DISCLAIMER: If configured improperly Solr might have an adverse effect on server security. Carefully setup your firewall to protect Solr from possible malicious actions. Amasty takes no responsibility for any possible damages to equipment or software, downtime or any losses.

March 21, 2016
March 31, 2016
December 18, 2015
Comments
Ashish @ MagikCommerce
October 28, 2014
Now, this is something. SOLR for a slow Magento to make searches superfast is an excellent idea. I am going to try this tonight.
Reply
Ksenia Dobreva
October 28, 2014
Glad you've found it useful!
Sagar
September 9, 2015
i dont have this folder as you specified above : /path/to/magento/install/lib/Apache/Solr/conf/ How can i get this folder in magento directory cp -r /path/to/magento/install/lib/Apache/Solr/conf/* apache-solr-3.4.0/example/solr/conf/
Reply
Ksenia Dobreva
September 14, 2015
Hey Sagar, thanks for asking. Please replace /path/to/magento/install with your actual path to magento installation directory. Hope that helps.
zhartaunik
November 9, 2015
Great thanks for this article. Everything is clear even for people who is not linux guru. Anyway I was faced with two issues during implementing and probably it can be helpful to anybody: 1. When I tried to start service, I got an error 'service unrecognized'. It happened because when I created init.d file - I didn't set execute permissions. At the first look its obviously, but I spent some time to find it. 2. Maybe I'm wrong, but as for me, magento configuration info is insufficient. When I entered host and port - I got connection error. I was also needed to set Solr Server Path = solr (as for me there was some another value)
Reply
Ksenia Dobreva
November 9, 2015
Hey there, many thanks for reading and sharing your thoughts. For permissions - it's a good suggestion and we will fix that in the article. As far as the second point is concerned, we need to check if this depends on Solr or Magento version, we'll investigate it in a couple of days and let you know/update the article as well.
JB Dc
March 13, 2017
Hi Can you help me with my SOLR installation? I followed all your steps however I ended up getting this error "can't find resource 'mapping-ISOLatin1Accent.txt' in classpath or '/data/www/client/solr_preprod/./conf/', cwd=/data/tomcat6 at org.apache.solr.core.SolrResourceLoader.openResource(SolrResourceLoader.java:273)" after copying this /path/to/magento/install/lib/Apache/Solr/conf/ to my SOLR installation
Reply
Ksenia Dobreva
March 29, 2017
Hey there and sorry for the late reply. I've checked with our specialists, but it's hard to say what's wrong from here. Maybe it will be a good idea to ask a specialist so he could perform the installation with full access to your site.
Konstantin Gerasimov
October 25, 2017
It should be noted that Magento 2.2 and future releases will not support Solr - http://devdocs.magento.com/guides/v2.0/config-guide/solr/solr-magento.html . Great article though!
Reply
Alina Bragina
January 22, 2018
Hi Konstantin, thanks for reading and leaving the useful addition!
James Burns
September 11, 2019
Looking at an article of the year 2016 easily describing Apache Solr functionalities, the installation and configuration process is a good thing. However, there is an addendum to Konstantin's information that from June 2020, Magento 1 will get permanently disabled. Thus, to get better search results at the Magento store, we need to get better in-site eCommerce search extensions.
Reply
Polina Litreyeva
September 13, 2019
Hello, James! Thanks for reading and sharing useful addition.
Leave your comment

Your email address will not be published

This blog was created with Amasty Blog Pro

This blog was created with Amasty Blog Pro