If you believe my posts will help someone please feel free to share.

Installing Solr on Amazon EC2 and using with Drupal 8

Solr requires a Java runtime environment so make sure this is on you server.

First see if Java is available.

You can try to run the java command and see if it is available to run.

It wasn’t for me so I needed to install Java in order to run Solr.

Now we are ready to install Apache Solr 7. Be sure you install the

This webpage will give you some download options. I simply chose the suggested mirror site.
http://www.apache.org/dyn/closer.lua/lucene/solr/7.6.0

SSH into your Amazon EC2 instance

You will be in the home directory of your main sudo user.

Download Apache Solr 7. You want the binary release not the source release.

I downloaded them both to show you the difference. You want to download and the use the one without the -src

We are going to make it easy on ourselves and extract the packaged solr installer.

We need to run the installer as root so sudo it is.

This will install Solr as a service on your EC2 machine, sets up a solr user and writes logs to /var/solr. It runs Solr on port 8983

You can check the Solr service is up and running by using the status command.

A few more things to tidy up here.

At this point, Solr is not running as the solr user but instead as the EC2 user with sudo privileges. We need to Solr running as solr.  You can check this in top.

where PID is the process id. The process id can be found from the Solr status command above.

So

When you restart Solr you will get a new process id. Look in top and make sure the Solr service running as solr.

Now you will be able to create new cores from the command line.

Creating Solr cores.

You will need to create a Solr core for your Drupal application.

Change your security group or firewall to open the port Solr is running on.

Now you need to revisit your Amazon AWS Security group and add a Custom TCP

It may look a like this:

This will allow you to access the Solr server by SSH and get a response from the URL on port 8983.

 

For better security you would lock this down. For example you might change the Solr port and only allow the source to be the IP of the server that is calling this Solr server. You might also make your SSH source only your home or office IP address. All this is way beyond the scope of this writing.

You can actually see you Solr instance running live by visiting your EC2’s public DNS url and appending the port Solr is running on.. It will look like this:

http://ec2-11-111-111-11.compute-1.amazonaws.com:8983

Bravo, but still a lot to do.

Set up Solr Search API on Drupal 8

On our Drupal application, install the  Solr Search API module using composer. You can do it through Drush or FTP, but composer will conveniently download all the dependencies ie other modules you need.

Then enable the following modules either with Drush or through the Drupal 8 admin web interface.

  • Search API
    • search_api
    • 8.x-1.11
  • Solr Search
    • search_api_solr
    •  8.x-2.4
  • Solr Search admin
    • search_api_solr_admin
    • 8.x-2.4

Navigate to http://yourdrupalsite.com/admin/config/search/search-api/add-server

Here you will add the details of the Solr server you just set up.

And we aren’t done yet. And to be honest this is where I start to get a little annoyed and usually give up.

This next part will be a bit messy and I am sure there a better best practice in how to do it but this worked for me.

Configuring your Solr Core for Drupal 8.

We are almost to the finish line. After setting up Solr, and then adding the modules and settings to Drupal 8, there is this moment where you think it will all magically come together and it doesn’t. To be quite honest, since Drupal 7 I usually just give up here, but tonight I didn’t.

Each Solr core can be configured to how you want to index and search the documents in the Solr index.

With an install as described above the core configuration can be found

The Solr Search API module provides configuration files to use for your Solr core. The trick is how to get the files moved from the Drupal 8 module directory to the Solr core directory. At a minimum these two sets of files have different user permissions. In this example, the Drupal solr configuration files and the solr core directory are on two different servers!

On the Solr server I navigated to the core’s directory and deleted all the files in the conf folder.

Then I download the Drupal 8 Solr Search Api zipped files for my Search API server. This can be found in a dropdown in the Drupal admin UI at /admin/config/search-api

 

Next I copied the zipped files from my local machine to my Solr server.

Unzipped to a folder I named /conf

Copied them to my core configuration folder

The trick part here is that the file ownership is root and I need them to be solr.

I didn’t have much patience left here so simply temporarily switched to the root user, navigated to the solr core configuration directory and change the files’ owner to solr.

Edit the new core configuration files.

Went back to my Drupal admin ready for it all to work. Unfortunately I was still seeing a warning about the solr core.

One more edit on the Solr server side of things. There is a properties file that needs to be edited.

I just simply removed the last line.

solr.install.dir=../../..