Magento 2.1.18 is the final 2.1.x release. After June 2019, Magento 2.1.x will no longer receive security patches, quality fixes, or documentation updates.
To maintain your site's performance, security, and PCI compliance, upgrade to the latest version of Magento.
Magento Commerce only

Configure Solr and Magento

Solr is deprecated in Magento 2.1 and will not be supported in 2.2. In a future release, Solr compatibility will be removed. If possible, use Elastic Search as an alternative catalog search engine.

The following topics discuss how to configure Solr to work with Magento Commerce:

Copy the Magento Solr configuration and start Solr

Magento comes packaged with a sample Solr configuration you can use and customize. To get started, you’ll copy the Magento configuration to Solr, replacing any existing files. After that you can start Solr and begin configuring Magento to work with it.

The example Solr configuration is not intended to be used in a production site. It’s for testing and development only. It’s simple to use which makes it a great way for you to learn more about Solr.

  1. As a user with root privileges, enter the following commands in the order shown to copy over the Solr configuration with the one packaged with Magento Commerce:

    1
    
    cd <your Solr install dir>/example/solr
    
    1
    
    cp -R collection1 magento2
    
    1
    
    cd magento2
    
    1
    
    cp -R <your Magento Commerce install dir>/vendor/magento/module-solr/conf/* ./conf/
    

    For example, if Solr is installed in /opt/solr/solr-4.10.4 and Magento Commerce is installed in /var/www/magento/html/magento2ee, enter:

    1
    
    cd /opt/solr/solr/solr-4.10.4/example/solr
    
    1
    
    cp -R collection1 magento2
    
    1
    
    cd magento2
    
    1
    
    cp -R /var/www/html/magento2ee/vendor/magento/module-solr/conf/* ./conf/
    

    If you’re prompted to overwrite files, try the command \cp -R <your Magento Commerce install dir>/vendor/magento/module-solr/conf/* ..

  2. After copying files, open the <your Solr install dir>/example/solr/magento2/core.properties file in a text editor and change:

    1
    
    name=collection1
    

    to

    1
    
    name=magento2
    

    More information about core.properties

  3. Save your changes to core.properties and exit the text editor.

  4. Task for Tomcat 6 with CentOS only

    If you’re using Tomcat 6 on CentOS, you must modify <your Solr install dir>/example/solr/conf/solrconfig.xml

    Locate the following line:

    1
    
    <dataDir>${solr.data.dir:./solr/data}</dataDir>
    

    Change it to:

    1
    
    <dataDir>${solr.data.dir:}</dataDir>
    
  5. Start Solr.

    As a user with root privileges, enter the following command to start Solr:

    1
    
    cd <your Solr install dir>/example
    
    1
    
    java -jar start.jar
    

    This method for starting Solr is for convenience and testing purposes only. In a production environment, you should start and stop Solr using a script as discussed in Script Solr startup and shutdown.

Configure Magento to work with Solr

This section discusses how to configure Magento Commerce to use the Solr search engine.

To configure Magento to work with Solr:

  1. Log in to the Magento Admin as an administrator.
  2. Click STORES > Settings > Configuration > CATALOG > Catalog > Catalog Search.
  3. In the right pane, expand Catalog Search.
  4. The following table shows the minimum amount of information to enter to test the connection to your Solr search engine. Leave all other values at their defaults.
Option Description
Search Engine Click Solr
Solr Server Hostname Enter the fully qualified hostname or IP address of the machine running Solr. (If Solr is running on the same host as Magento, you can optionally use localhost.)
Solr Server Port Enter Solr's listen port. (The example Jetty servlet container uses 8983. The default for Tomcat is usually 8080.)
Solr Server Username Optional. Enter a username for Solr authentication, if desired.
Solr Server Password Optional. Enter the user's password, if required.
Solr Server Timeout Enter a connection timeout value, in seconds.
Solr Server Path

Specifies the path and name of the Solr web application. The path used by the example Solr configuration is solr/magento2.

If you customized Solr, the value you enter in this field must exactly match the value of webapp_name=<value> in <your Solr install dir>/example/solr/magento2/conf/conf/scripts.conf

.

The following figure shows an example. Configure Magento to use Solr

Click Test Connection.

The button changes as follows.

Button state Meaning
The test connection succeeded. Click Save Config and continue with the next section.

The test connection failed. Try the following:

  • Examine the command window in which you started Solr for stack traces and exceptions. You must resolve those before you continue.
    In particular, make sure you started Solr as a user with root privileges.
  • Verify that allow_url_fopen = On is present in your server's php.ini.
    If you are not sure where php.ini is located, you can create a phpinfo.php page to locate it.
  • Make sure that UNIX firewall and SELinux are both disabled, or set up rules to enable Solr and Magento to communicate with each other.
  • Verify the value of the Solr Server Hostname field. Make sure the server is available. You can try the server's IP address instead.
  • Use the command netstat -an | grep listen-port command to verify that the port specified in the Solr Server Port field is not being used by another process.
    For example, to see if Solr is running on its default port, use the following command:
    netstat -an | grep 8983
    If Solr is running on port 8983, it displays similar to the following:
    tcp        0      0 :::8983            :::*          LISTEN
  • If Solr is installed on a remote machine, use the ping command to verify that machine is reachable from your Magento server.

Only after the test connection succeeds, click Save Config< and continue with the next section.

Reindexing catalog search and refreshing the full page cache

After you change Magento’s Solr configuration, you must reindex the catalog search index and refresh the full page using the Admin or command line.

To refresh the cache using the Admin:

  1. In the Admin, click System > Cache Management.
  2. Select the checkbox next to Page Cache.
  3. From the Actions list in the upper right, click Refresh.
    The following figure shows an example.

To clean the cache using the command line, use the magento cache:clean command.

To reindex using the command line:

  1. Log in to your Magento server as, or switch to, the Magento file system owner.
  2. Enter the following command to reindex all indexers:

    1
    
    php <magento_root>/bin/magento indexer:reindex
    

    Enter the following command to reindex the catalog search index only:

    1
    
    php <magento_root>/bin/magento indexer:reindex catalogsearch_fulltext
    
  3. Wait while the indexers are reindexed.

Unlike the cache, indexers are updated by a cron job. Make sure cron is enabled before you start using Solr.

Verify Solr is working

To verify Solr works, go to the storefront and search for any term (including one that won’t return results) and look for the search in the Solr command window.

The following figure shows an example of a storefront search.

Verify Solr works by searching the storefront

The following excerpt from the Solr command window shows the same search:

1
497008 [qtp2032251042-13] INFO  org.apache.solr.core.SolrCore  – [magento2] webapp=/solr path=/select params={facet.field={!key%3Dcategory_bucket}category_ids&json.nl=flat&fl=id,score&start=0&fq=store_id:1&rows=10000&q=sku:((hello*+hello))+OR+fulltext_en:((hello*+hello))+OR+attr_color_en:((hello*+hello))+OR+attr_description_en:((hello*+hello))+OR+attr_manufacturer_en:((hello*+hello))+OR+attr_name_en:((hello*+hello))+OR+attr_short_description_en:((hello*+hello))+OR+attr_status_en:((hello*+hello))+OR+attr_tax_class_id_en:((hello*+hello))&f.category_ids.facet.mincount=1&omitHeader=true&stats=true&wt=json&facet=true&stats.field=price_0_1} hits=0 status=0 QTime=58

Next step

Prepare Solr for production

Updated