Setting Up Apache Solr to Work With Drupal 7 on Lando

Quick guide on getting Solr search working with Drupal 7/8/9 on Lando.

A few out of date articles are online on Apache Solr working with Drupal on Lando. Google et al will give you a few close recipes for Drupal 8 but have some errors. The sequence below is tweaked for Drupal 7 - pretty similar approach for Drupal 8, although you can use a newer version of Solr with D8/9.

You need to alter .lando.yml to following:

name: drupalproject
recipe: drupal7
config:
  webroot: docroot
# Get nice url's for each service.
proxy:
  search:
    - admin.solr.lndo.site:8983
services:
  # Solr
  # Spin up a Solr container called "search".
  search:
    # Use a specific Solr version.
    type: solr:6.6
    # Optionally declare the name of the Solr core.
    # This setting is only applicable for versions 5.5 and above.
    core: drupal7
    # Optionally allow access at localhost:9999.
    # You will need to make sure port 9999 is open on your machine.
    # You can also set `portforward: true` to have Lando dynamically assign a port.
    # Unlike specifying an actual port setting this to true will give you
    # a different port every time you restart your app.
    portforward: 9999
    # Optionally use custom Solr config files eg (schema.xml and solrconfig.xml).
    # This is relative to the app root (which may be different from your webroot).
    # This should be the directory containing the schema.xml and solrconfig.xml files, not the path to a certain file.
    config:
      dir: docroot/sites/all/modules/contrib/search_api_solr/solr-conf/6.x

Then start Lando instance and you need to copy files via Docker (replace the 'drupalproject' bit of 'drupalproject_search_1:/' with your Lando project name (first line of .lando.yml). Be conscious of the location of your search_api_solr files and which version of Solr you are using. You then need to SSH into your Lando instance to move some of the files about. Don't forget to restart Lando:

docker cp docroot/sites/all/modules/contrib/search_api_solr/solr-conf/6.x drupalproject_search_1:/opt/solr/server/solr/mycores/drupal7
lando ssh -s search
cd /opt/solr/server/solr/mycores/drupal7
mv conf conf.bak && mv 6.x conf
exit
lando restart

Then you need to configure your Drupal Search API Server with following:

You can also use Search API Solr Overrides module and change settings.php:

 

/**
 *
 * Local override for Solr
 * Using Search API Solr Overrides module
 *
 */
$conf['search_api_solr_overrides'] = array(
  'documents_solr' => array(
    'name' => 'Solr documents (Overridden)',
    'options' => array(
      'host' => 'search',
      'path' => '/solr/drupal7',
      'port' => 8983,
    ),
  ),
);

Inspiration for this came from https://github.com/lando/lando/issues/1772