1
votes

From @DamienMcKenna in Slack

Having problems creating a Solr instance with a D7 site. I copied the conf files to ~/.ddev/solr/conf but when Solr starts there is no default instance created. I ran ddev stop --remove-data --omit-snapshot and recreated the instance, but the instance still doesn't exist. When I go to the Solr UI to check the system it shows "no cores available", when I try to create one named "dev" it says:

Error CREATEing SolrCore 'dev': Unable to create core [dev] Caused by: Can't find resource 'solrconfig.xml' in classpath or '/opt/solr/server/solr/dev'

1

1 Answers

2
votes

I had success on a Drupal 7 project using the example docker-compose-solr.yaml file from version 1.11.0 of DDEV.

  1. Copy https://github.com/drud/ddev/blob/v1.11.0/pkg/servicetest/testdata/services/docker-compose.solr.yaml into your .ddev folder and ensure line 34 matches the solr version you're going to copy from step 2 below, eg solr: 6.6

  2. Copy the files from sites/all/modules/contrib/search_api_solr/solr-conf/6.x/*.* into the .ddev/solr/conf folder.

  3. Download and enable search_api_override module.

  4. Add the following in settings.local.php:

    // For ddev only.
    $conf['search_api_override_mode'] = 'load';
    $conf['search_api_override_servers']['content'] = array(
      'name' => 'DDEV: Solr Server',
      'options' => array(
        'host' => 'solr',
        'port' => '8983',
        'path' => '/solr/dev',
        'http_user' => '',
        'http_pass' => '',
        'excerpt' => 0,
        'retrieve_data' => 1,
        'highlight_data' => 0,
        'http_method' => 'AUTO',
      ),
    );
    

    Also, ymmv. It may be better to only override the values you need individually… a la:

    $conf['search_api_override_servers']['content']['options']['host'] = 'solr';
    $conf['search_api_override_servers']['content']['options']['port'] = '8983';
    $conf['search_api_override_servers']['content']['options']['host'] = '/solr/dev';
    

    You may need to modify 'content' array index to match whatever you configured in Drupal 7 to be your Solr index's machine name.

  5. Start ddev with ddev start.

NOTE, I place the Search API override values in sites/default/settings.local.php instead of what one would think to be the logical place (sites/default/settings.ddev.php) so as not to interfere with DDEV's own auto-generation of the latter file.

It would be cool if DDEV did this automatically in settings.ddev.php similar to how the DB service settings work, but AFAICT this level of integration is not there and likely never will be for Drupal 7. Firstly, because you need an additional module (search_api_override) that may or may not be present, and secondly because users have the ability to name their Solr server whatever they want, so it would be hard to automate that. E.g. $conf['search_api_override_servers']['content'] could be anything like: $conf['search_api_override_servers']['foo'].