|
| 1 | +# Apache Solr (Cloud) Integration for DDEV-Local |
| 2 | + |
| 3 | +Running Solr in single core mode is not the recommended way anymore. The "Solr |
| 4 | +Cloud" mode is the preferred way and offers many additional features like |
| 5 | +Streaming Expressions and APIs that make management easier. These APIs allow to |
| 6 | +create and modify collections (cores), manage stopwords, synonyms etc. |
| 7 | +All from Drupal via UI or drush, via the Solarium library or your custom code. |
| 8 | +That’s a huge difference compared to Solr maintenance like you know it before! |
| 9 | + |
| 10 | +In a production environment it is recommended to have at least three Solr nodes |
| 11 | +that build that "cloud". In a development environment you can choose to only run |
| 12 | +a single node in standalone mode to require less memory or CPU. DDEV offers both |
| 13 | +options. You choose to run three nodes or a single node in standalone mode by |
| 14 | +copying either `docker-compose.solr.yaml` or |
| 15 | +`docker-compose.solr-standalone.yaml` to your project's `.ddev` folder. |
| 16 | + |
| 17 | +Solr Cloud provides a lot of APIs to manage your collections, cores, schemas |
| 18 | +etc. Some of these APIs require a so-called "trusted" context. Solr therefore |
| 19 | +supports different technologies for authentication and authorization. The |
| 20 | +easiest one to configure is "Basic Authentication". This DDEV service comes with |
| 21 | +a simple pre-configured `security.json` to provide such a trusted context based |
| 22 | +on basic authentication. It creates a single administrative account full access |
| 23 | +rights: |
| 24 | +* user: `solr` |
| 25 | +* password: `SolrRocks` |
| 26 | + |
| 27 | +Just copy the `solr` directory (including `security.json`) to your |
| 28 | +project's `.ddev` folder. If required, you can adjust the username and the |
| 29 | +password by editing the `security.json` file and restarting the service. But be |
| 30 | +aware that the password is stored as a hash. Please consult the Solr |
| 31 | +documentation for details. On the other hand our recommendation for a local |
| 32 | +development environment is to just stay with the default. |
| 33 | + |
| 34 | +Once up and running you can access Solr's UI within your browser by opening |
| 35 | +`http://<projectname>.ddev.site:8983`. For example, if the project is named |
| 36 | +"myproject" the hostname will be `http://myproject.ddev.site:8983`. To access |
| 37 | +the Solr container from the web container use `ddev-<project>-solr:8983`. |
| 38 | + |
| 39 | +Solr Cloud depends on Zookeeper to share configurations between the Solr nodes. |
| 40 | +Therefore this service starts a single Zookeeper server on port 2181, too. It is |
| 41 | +also required if you decide to run this service in standalone mode using a |
| 42 | +single node only. But there's nothing you need to care about. This is just for |
| 43 | +your information in case you wonder what that service is. |
| 44 | + |
| 45 | +## Drupal and Search API Solr |
| 46 | + |
| 47 | +For Drupal and Search API Solr you need to configure a Search API server using |
| 48 | +Solr as backend and `Solr Cloud with Basic Auth` as its connector. As mentioned |
| 49 | +above, username "solr" and password "SolrRocks" are the pre-configured |
| 50 | +credentials for Basic Authentication in `.ddev/solr/security.json`. |
| 51 | + |
| 52 | +Solr requires a Drupal-specific configset for any collection that should be used |
| 53 | +to index Drupal's content. (In Solr Cloud "collections" are the equivalent to |
| 54 | +"cores" in classic Solr installations. Actually a collection consists of |
| 55 | +multiple cores sharded across all server nodes.) |
| 56 | +Starting from Search API Solr module version 4.2.1 you don't need to deal with |
| 57 | +configsets manually anymore. Just enable the `search_api_solr_admin` sub-module |
| 58 | +which is part of Search API Solr. Now you create or update your "collections" at |
| 59 | +any time by clicking the "Upload Configset" button on the Search API server |
| 60 | +details page, or automate things using |
| 61 | +``` |
| 62 | +ddev drush search-api-solr:upload-configset SERVER_ID NUMBER_OF_SHARDS |
| 63 | +``` |
| 64 | + |
| 65 | +Note: If you choose to run Solr Cloud using a single node in standalone mode, |
| 66 | + you need to limit the number of "shards" to "1" when uploading the |
| 67 | + configset. There's a corresponding option in the UI and a parameter for |
| 68 | + the drush command. |
| 69 | + |
| 70 | +## Installation step by step |
| 71 | + |
| 72 | +1. Copy `docker-compose.solr.yaml` **or** `docker-compose.solr-standalone.yaml` to your project's `.ddev` directory. |
| 73 | +2. Copy the `solr` folder (`including security.json`) to your project's `.ddev` directory. |
| 74 | +3. Configure your application to connect Solr at `http://ddev-<project>-solr:8983`. |
| 75 | +4. If you want to use Solr's APIs that require a trusted context configure Basic Auth with username `solr` and password `SolrRocks`. |
| 76 | +5. (Re-)start your DDEV project. |
| 77 | + |
| 78 | +## Solarium |
| 79 | + |
| 80 | +[Solarium](https://github.com/solariumphp/solarium) is the leading Solr |
| 81 | +integration library for PHP. It is used by the modules and integrations of many |
| 82 | +PHP frameworks and CMS like Drupal, Typo3, Wordpress, Symfony, Laravel, ... |
| 83 | +If you build your own PHP application and want to use Solarium directly, here is |
| 84 | +an example of how to configure the connection in DDEV. |
| 85 | + |
| 86 | +```php |
| 87 | +use Solarium\Core\Client\Adapter\Curl; |
| 88 | +use Symfony\Component\EventDispatcher\EventDispatcher; |
| 89 | + |
| 90 | +$adapter = new Curl(); |
| 91 | +$eventDispatcher = new EventDispatcher(); |
| 92 | +$config = [ |
| 93 | + 'endpoint' => [ |
| 94 | + 'localhost' => [ |
| 95 | + // Replace <project> by your project's name: |
| 96 | + 'host' => 'ddev-<project>-solr', |
| 97 | + 'port' => 8983, |
| 98 | + 'path' => '/', |
| 99 | + // Use your collection name here: |
| 100 | + 'collection' => 'techproducts', |
| 101 | + 'username' => 'solr', |
| 102 | + 'password' => 'SolrRocks', |
| 103 | + ) |
| 104 | + ) |
| 105 | +); |
| 106 | + |
| 107 | +$client = new Solarium\Client($adapter, $eventDispatcher, $config); |
| 108 | +``` |
| 109 | + |
| 110 | +## Drupal and Search API Solr (>= 4.2.1) |
| 111 | + |
| 112 | +* Enable the `search_api_solr_admin` module. (This sub-module is included in Search API Solr >= 4.2.1) |
| 113 | +* Create a search server using the Solr backend and select `Solr Cloud with Basic Auth` as connector: |
| 114 | + * HTTP protocol: `http` |
| 115 | + * Solr node: `ddev-<project>-solr` (Replace <project> by your project's name.) |
| 116 | + * Solr port: `8983` |
| 117 | + * Solr path: `/` |
| 118 | + * Default Solr collection: `techproducts` (You can define any name here. The collection will be created automatically.) |
| 119 | + * Username: `solr` |
| 120 | + * Password: `SolrRocks` |
| 121 | +* Press the `Upload Configset` button on the server's view and check the "Upload (and overwrite) configset" checkbox. |
| 122 | +* Set the number of shards to _3_ if you use `docker-compose.solr.yaml` or _1_ if you use `docker-compose.solr-standalone.yaml`. |
| 123 | +* Press `Upload`. |
| 124 | + |
| 125 | +### Drupal and Search API Solr 4.1 and older |
| 126 | + |
| 127 | +It is highly recommended to upgrade to the 4.2 version. But if you're required |
| 128 | +to use an older versions of the Search API Solr module you have to deploy the |
| 129 | +configset manually and create a collection using this configset afterwards. |
| 130 | +Therefore you need to use the `Download config.zip` function of Search API Solr. |
| 131 | +Please consult the Solr documention about the different ways about how to deploy |
| 132 | +configset archive and how to create a collection using it. |
| 133 | + |
| 134 | + |
| 135 | +**Contributed by [@mkalkbrenner](https://github.com/mkalkbrenner)** |
0 commit comments