How to Install Apache Solr on a Drupal 8 Website using SearchStax by Measured Search
SearchStax® by Measured Search® can be used to enable Apache Solr on a Drupal 8 website using Drupal's Search API and its Search API Solr plugins.
This article was based on a blog post by by Thomas Hada of Anant.
This example uses Drupal 8.3 and Solr 6.4.2. There is also a page for Drupal 7.
- Create a new deployment in SearchStax.
- Upload a custom configuration to your Solr Server.
- Install Drupal.
- Install the Search API and Search API Solr plugins.
- Configure the Search API Solr plugin.
- Add sample content.
- Optional - Manually Index Your Site.
Step 1: Create a New Deployment in SearchStax
Assuming you have already created a SearchStax account and do not already have a deployment set up, click on the Deployments tab and then click on the Create New Deployment button at the top. Enter a deployment name, and select the most appropriate region, plan, and Solr version for your needs. In this example we will be using Solr 6.4.2.
Once you create your deployment, you will see it in the Deployments dashboard.
Clicking on the name of the deployment will give you pertinent information about your deployment's servers. The Solr Load Balancer URL will take you to your Solr server dashboard.
Step 2: Upload a Custom Configuration to Your Solr Server
Download the Search API Solr plugin files: https://www.drupal.org/project/search_api_solr
Included in the Search API Solr download are several configurations in the solr-conf
folder, with subfolders 4.x, 5.x, and 6.x for the respective Solr versions.
SearchStax uses Apache ZooKeeper for maintaining configuration information. Upload the appropriate configuration files via Zookeeper and create a new collection. If you have your Zookeeper script already, the two commands you will need are as follows:
> ./zkcli.sh -zkhost <zookeeper URL> -cmd upconfig -confdir <Solr configuration> -confname <configuration name>
$ zkcli.bat -zkhost <zookeeper URL> -cmd upconfig -confdir <Solr configuration> -confname <configuration name>
Create New Collection:
> curl '<Load Balancer URL>admin/collections?action=CREATE&name=<collectionName>&collection.configName=<configName>&numShards=1'
$ curl.exe "<Load Balancer URL>admin/collections?action=CREATE&name=<collectionName>&collection.configName=<configName>&numShards=1" -k
Detailed instructions on uploading a new configuration and creating a new collection for a Solr deployment can be found at Solr-as-a-Service Quick Start.
Once complete, go into your Solr dashboard. There will be a newly created core based on the name of the collection name you defined when uploading the configuration. Make note of this core name.
Step 3: Install Drupal
If you do not already have one, there are many ways to create your own Drupal instance. Some web hosting services offer specialized integrations and setup options that help streamline the process. Here we used GoDaddy's Cloud Server services, which in a few clicks can create a hosted Drupal website.
Step 4: Install Search API / Search API Solr plugin
Go to your Drupal website and log in.
Open up a new tab in your web browser, then go to: https://www.drupal.org/project/search_api. Once there, scroll down to find the different download links. Right click on the appropriate download link to the compressed file, and copy the link address.
In your Drupal site, either navigate to the /admin/modules page or click the Extend tab at the top. Then click Install New Module.
Paste the link address copied earlier into the Install from a URL text field, and then click the Install button.
Once complete, you should see a confirmation message saying that the installation was complete.
If you see this, then you can install the Solr plugin for Search API: https://www.drupal.org/project/search_api_solr. Install this in the same way as above.
Before continuing, you may need to install the Search API Solr composer dependencies. See https://www.drupal.org/documentation/install/composer-dependencies for instructions on how to do this.
Next, you will need to enable the installed modules. Click Enable newly added modules, or click on the Extend tab. Scroll down to the section called Search to see new module settings.
Enable the following items: Search API, Solr search, and Solr Search Defaults.
Then click Install at the bottom of the page. You should see this confirmation:
Once complete, it is recommended to uninstall the Solr Search Defaults module, as it may affect performance. Uninstalling the module will not remove the provided configurations.
Step 5: Configure the Search API Solr Plugin
Now that the modules have been enabled, click on the Configuration tab. Look for
section SEARCH AND METADATA and click on Search API to configure it.
Once there, click Add Server.
Give your server a name, make sure the Backend is set to Solr, and configure your Solr Backend. Check that HTTP protocol is set to "https", the Solr host and Solr port are correct, and you set the Solr core that was created after uploading your Solr configuration.
If your configuration settings are valid, you will see a message saying that the information was saved successfully.
Next you will need to define an index. In the Search API configuration screen, click on Add Index.
Give your index a name, and select the data sources you wish to index. For this example, select Comment and Content. Also, at the bottom of the page make sure that you select the Server created earlier.
Step 6: Add Sample Content
Install the Devel plugin using the same method as described in Step 4: https://www.drupal.org/project/devel. Then, enable Devel and Devel generate.
You will see new options in multiple menus. Go to Manage > Configuration, and scroll down to the Development section. Here you have options to Generate content via Devel.
Click on Generate Content.
Select a Content Type and enter the number of nodes. For example, selecting Article and typing "20" nodes will produce 20 new articles filled with dummy data.
Step 7: Optional - Manually Index Your Site
A cron job will periodically index your site automatically, but if you want to see your results immediately go to the Search API configuration screen and click on the index created earlier. At the bottom, click on the Index now button.
After you begin, you will see a progress bar. Once it reaches 100%, you will get a success message.
After your site has been indexed, you can view and query the data in Solr.
Congratulations! You have now customized your Drupal website to allow for content to be indexed in your SearchStax Solr deployment.