I can’t stand being stagnant, every day is a new opportunity to achieve something, even on a small scale
– Benjamin Stone
If your problem statement states : “Run a group of affiliated sites from one Drupal installation and a single shared database in a way that the site should be accessible from multiple domains and should also have different content, theme or blocks!!”
Then “Domain Access” is the solution for you.
What is Domain Access ?
According the module documentation : The Domain Access project is a suite of modules that provide tools for running a group of affiliated sites from one Drupal installation and a single shared database. The module allows you to share users, content, and configurations across a group of sites such as:
By default, these sites share all tables in your Drupal installation.
In simple words, it lets you create a site with multiple subdomains and provide content access to each domain as per the requirement.
We came across this module while working on a News publication project, where we were supposed to create a site that should be accessible from different domains and should have different content, themes, blocks, users but should share same database so that the content relevant to a specific domain should be featured on homepage while other content would be placed on different block regions that are not vital to a specific domains.
The main motive of this blog is to :
- Provide help for integrating domain access with Drupal 8 site as we struggled a lot while looking for a helpful blog or a document.
- We will also try to look into some of the important features that will help you to make a decision whether or not you should use this module for your implementation.
Let’s start by installing and configuring multiple domains on our local environment.
Note: For the demo purposes my local site is hosted on vagrant server and I am using Acquia BLT installation. Acquia BLT (Build and Launch Tool) provides an automation layer for testing, building, and launching Drupal 8 applications. To learn more about Acquia BLT and it’s setup , read the documentation here .
Installation and Configuration :
Assuming that we now have our BLT setup on our local machines, we can now move ahead and download the domain acces module from here , or you can simply run command :
The Domain Access Suite comes with the following modules:
- domain_content ,
- Head towards the admin/modules admin page and install the above listed modules.
- Before going ahead and looking into the configuration, head towards the project root and edit the “services.yml” file and add the following value to match the root hostname of your sites, to use cross-domain logins, you must set the *cookie_domain* value.
- Now head towards the domain module configuration, “/admin/config/domain” , click on the “add domain record” button, you should be redirected to domain add page.
- To create a domain record, you must provide the following information:
- A unique *hostname*, which may include a port. (Therefore, example.com and example.com:8080 are considered different.) The hostname may only contain alphanumeric characters, dashes, dots, and one colon.
- A *machine_name* that must be unique. This value will be autogenerated and cannot be edited once created.
- A *name* to be used in lists of domains.
- A URL scheme, used for writing links to the domain. The scheme may be `http`,`https`, or `variable`.
- A *status* indicating `active` or `inactive`. Inactive domains may only be viewed by users with permission to `view inactive domains` all other users will be redirected to the default domain.
- The *weight* to be used when sorting domains. These values autoincrement as new domains are created.
- Whether the domain is the *default* or not. Only one domain can be set as`default`. The default domain is used for redirects in cases where other domains are either restricted (inactive) or fail to load.
Add another URL using the same steps, in our case example : mysite1.local.blt-project.com, mysite2.local.blt-project.com.
- Now add the URLs in /etc/hosts files to access the subdomains and restart the server. You should now be able to access all domains.
Congratulations!! you now have your first subdomain site ready!!
In case it was difficult to get it done using the steps above, follow the video link below to successfully configure the subdomains :
Content Creation and Publishing:
- The module comes with configuration to allow the content to displayed on multiple domains or restrict a specific content to be available at a specific domain. For ex. Content A might be visible to site visitors of Domain A, but Not visible to Site Visitors of Domain B . The module provides following options to be applied on the node, to be or not to be available across multiple domains. :
- It also provides an admin interface where I can see the list of contents created at different domains.
Theme and Site Settings:
- There are 2 contributed modules developed by community to provide interface to change themes and site settings .
- You can choose to install the modules and change the themes of all domains accordingly or this can be managed through domain specific configuration files which can be imported via specific names such as : “domain.config.DOMAIN_MACHINE_NAME.LANGCODE.item.name“.
Domain Blocks :
- This module in not available in drupal 8, but since themes can be changed and can be kept as domain specific, the block regions can be changed for both domains based upon themes. (Or we can programmatically hide or display a block based upon Domain ID, using Domain API .)
Manage Content display on a page according to domains:
- I created a View named as “Domain Specific” , it comes with number of filter criterias based upon which view will filter the result . One of the most useful filters is the “Available on this Domain“. This filter will display only that content which will be displayed only on domain which the content is associated to. This can help in creating page with different contents based upon thier availability.
- The module Domain Taxonomy and Domain Access Taxonomy is not available in drupal 8 for this, we can create a Vocabulary which will contain terms and a field named “Domains” as select options , and using the API or the domain ID, the term will be accessible or can be accessed only if the domain ID matches with the selected domain option.
What do we know and what have learnt ?
The Domain access for Drupal 8 is still in it’s development mode where some of the major features are available to get started with and to get the subdomains live on drupal 8 site, but in Drupal 7 there are lot of modules that extend the functionality of Domain Access module and provides unlimited features to manage everything from the interface itself.
Drupal 8 might require some work from Developer’s end to get the full fledged functionality up and running. Do let me know what are your thoughts about the module and is there a better way to achieve creating subdomain other than Domain Access module.
Thank You !!