74% of all web traffic originates from search. Search and performance are KEY to a web site's success. The advanced search features and performance on popular services such as Youtube and Google have set the bar as far as user experience is concerned. Drupal 8 and Apache Solr (Search) gives a user experience of performance, fast advanced search features and related content capacity.
In this article I walk through my process of setting up Apache Solar on Drupal 8. This article in particular covers the; I found; rather cryptic process of configuring the server. Enjoy.
The article assumes that there is an instance of Apache Solr running on the server. If not it will first need to be installed on the server. Apace Solr Download
The modules needed
Use Composer to require the following modules:
Search Api (search_api)
This module provides a framework for easily creating searches on any entity known to Drupal, using any kind of search engine. For site administrators, it is a great alternative to other search solutions, since it already incorporates facetting support and the ability to use the Views module for displaying search results, filters, etc. Also, with the Apache Solr integration, a high-performance search engine is available for this module.
Search API Solr (search_api_solr)
This module provides a Solr backend for the Search API module.
This article was based on Drupal 8 using Search API Solr 8.x-3x
Summary of steps
My configuration setup followed the following steps:
- Install and set up Apache Solr server on Ubuntu.
- Test that Apache Solr Server is running.
- Uninstall the default Drupal Search module.
drush pm:uninstall search
- Use Composer to install the modules mentioned above
composer require drupal/MODULE
drush en -yto enable the following modules:
- Search API
- Search API Solr
- Search API Solr Admin (sub-module of Search API Solr)
- Search API Solr Search Defaults (sub-module of Search AP Solr)
Enable this module for a best-practice default setup of Search API with the Solr backend. After installation it is recommended to uninstall this module again for performance reasons. The provided configuration will not be removed.
- Configure Solr Server to work with Drupal 8
Test that the Solr Server is running.
From the command line run:
sudo systemctl status solr.service
If the Solr Server is running you should seethe following line in your output:
Active: active (exited) since Mon 2020-02-24 15:39:54 UTC; 31min ago
Apache Solr terminology
Understanding terminology in a name space often helps to understand processes.Let us look at a few terms:
- Distributed search: a search engine technique that uses many computers and networks to handle search related tasks.
- Non-distributed search: antithesis of distributed search and implies a single Solr Server Instance.
- In distributed search a collection is a logical index spread across multiple servers.
- In non-distributed, a single server can have multiple collections and each collection is also a core.
- Core: Is that part of the server which runs one collection (distributed search). In non-distributed core and collection are the same.
Configure Solr Server to work with Drupal 8
Because we installed Search API Solr Search Defaults, this will set up a best-practice default setup of Search API with the Solr backend. In part it will create your first Solr core/collection named collection1.
Search configuration is found at:
You should see something like the image below.
Check the configuration of your Solr Server by clicking the 'Edit' button under 'Operations'. Now, even though Status indicates all is ok, you may, and if this is the first time you are using Solr on your D8 site, you probably will see errors like:
Or with in the status report:
What you need to do is copy the D8 Search API Solr configuration files to the collection1 directory environment within the installation files of the Solr Server running on your web server.
Click the 'Get config.zip' button to download a .zip file of the required configuration files. I then upload and unpack the archive to my Drupal configuration folder. This will be deleted once Solr is up and running.
Configure Solr Server - part 2
To continue, you need to know where your collection is located on your server. To do this go to the Solr Admin screen located at:
Click 'Core Admin' and find the instanceDir value. On Ubuntu this is:
SSH in to your server and become the root user: sudo su
Locate yourself in your collection1 directory: cd /var/solr/data/collection1 and you should see something like:
drwxrwxr-x 6 solr solr 4096 Feb 25 11:16 . drwxr-x--- 3 solr solr 4096 Sep 4 07:32 .. drwxrwxr-x 2 solr solr 4096 Feb 24 15:38 conf -rw-rw-r-- 1 solr solr 81 Feb 25 07:06 core.properties drwxrwxr-x 6 solr solr 4096 Sep 7 10:08 data
Rename conf to conf.old mv conf conf.old.
Copy the configuration that was just uploaded
cp -R /pathtoserver/yourwebsite.com/config/conf/ /var/solr/data/collection1/
Change owner of the copied conf chown solr:solr -R conf
Change permission of copied conf chmod 755 -R conf
Modify the solr.install.dir value of the copied
conf/solrcore.properties file from solr.install.dir=../../.. to solr.install.dir=/opt/solr
Restart the Solr server systemctl restart solr.service
Reload the Solr Server configuration page of your Drupal site and you should now see configuration settings for a Solr server that is running correctly.
NOTE: The Solr admin page located on :8983/solr is open to the public and must be protected for production environments.
This follow up article covers setting up a search using the Solr server as well as setting up search facets.
Hi I am Daniel.
I am a beginner in Drupal. I use the Acquia DevDesktop to implement a Drupal (v. 8.9) Website.
I wanted to use Solr Search. But if I want to install it I get an error which says:
"Solr search requires the solarium/solarium library."
Can you help me how to fix this?
Using Composer to install the Solarium library should fix this.
composer require solarium/solarium