The Domain access module allows us to configure Drupal in such a way that we can build multiple websites with a single core installation. These multiple portals are obtained based on the access to the portal through different URLs, therefore, we will only have a single website to manage (as opposite to the core functionality of Drupal where we will only have one website and a single database).
The audience for this manual are those people who know the DNS performance (basic knowledge). In relation to Drupal, it is directed to any public as it explains the interface procedure. One of the advantages of this module is the ease of managing the configuration of the different domains, because every web portal access the same database, which can affect the overall performance of the portal site.
Domain access functionality is based on the access to the portal through different domains, for example, if we access the domain “domain.com”, the determined configuration will load for that domain, and if we enter “subdomain.com”, a different configuration to the previous one will load. It can be like the performance of the default Drupal multisite, although in this case, we will not have different files for additional sites or databases. In addition to the module configuration in Drupal, both the server serving the portal and the DNS server must be properly configured so that all URLs point to the same Drupal installation.
First of all, we will detail the scenario where we will start from to carry out the correct module configuration:
- A configured apache virtualhost pointing to the path where Drupal has been downloaded.
- A clean installation of Drupal 7.43
- The Domain access module (7.x-3.12) downloaded at: sites / all / modules
In order to test the configuration module correctly, the first thing to do will be to modify the created virtualhost and add the following parameters:
ServerName domain.local ServerAlias subdomain.local
Once added these parameters, we will have to restart the web server (in this case, Apache).
The next step would be to configure the DNS server for both domain.local and subdomain.local to point to the same site. In order to see the test performance (and as we do not have a DNS server in the local environment), we will modify the hosts file so that these URLs point to our settings. To do this, we will open the hosts file (/ etc / hosts in ubuntu) and we will add the following lines:
127.0.0.1 domain.local 127.0.0.1 subdomain.local
Once completed, we will have our local server configured to serve both URLs.
At this point, we have already our server correctly configured and, although in an unreal way, the URLs will be pointing to that server. At this moment, we can configure Drupal to have both domains running Domain access. We should download the module in sites / all / modules. Before activating the module, it will be necessary to modify the Drupal settings.php (sites / default / settings.php) by adding the following code lines:
/** * Add the domain module setup routine. */ include DRUPAL_ROOT . '/sites/all/modules/domain/settings.inc';
This will cause that when the Drupal bootstrap is loaded, the configuration of the Domain module is also loaded. Once added the previous code lines, we will proceed to activate the module Domain access (to enable the module through Drush it will have to indicate as an argument the current default domain: drush pm-enable domain --uri = domain.local) through the interface (it is highly recommended to do so):
Once the module is enabled, the system will request to rebuild the permissions displaying the following message (we can also do this from the admin / reports / status URL):
We will click on the link seen in the image above, we will confirm the action and we will have the module enabled. The next step will be to generate the configuration for the second domain. To do this we must go to the following URL:
Admin / structure / domain
Once we have entered the module configuration, we can see an interface as the following one:
At this moment, we select the link “create domain” and we will configure the options for the second website with a different domain.
The options that we must set up for the configured domains in our virtualhost are the following ones:
1. Domain name. This is the one that we have previously configured in the virtualhost and in the host file.
2. Identifying name. It will be the name that we will put the domain to identify them.
3. URL scheme. we should indicate here whether or not the domain uses https.
The rest of options can be left by default, although we can modify, as we can see in the image below, both the new domain state and its weight in relation to others and whether it will be the default domain or not. We will apply the changes and we will already have both domains or portals working. We will see below the differences on the main page of each site:
Although the module configuration to support two domains is already completed, it will be necessary to take into account a last configuration feature, in order not to get surprised when testing both portals with admin users. In order the changes not to be reflected in both "portals", by default the module makes the admin users see the content on both pages, although this can be modified in a click of a button. To do so, we will enter the following URL:
Admin / structure / domain / settings
And then, we will modify the option 'Enforce rules on administrators' as we can see in the image below:
We apply the changes and we already have the two portals totally isolated for both anonymous users and those ones logged as administrators (this change is optional).