About

Since static HTML does not contain any executable code, it would be a nice idea to separate production websites from the actual development of the website by having Drupal export the entire website to a static counterpart.

Luckily, one such module exists for Drupal named Tome with which periodic and automated exports can be created such that development can take place on the development website whilst users will browse the statically generated website.

This tutorial just touches on the Tome module installation yet rather focuses on an automated setup for exporting dynamic websites created with Drupal.

Overview

The proposed solution assumes that the website will be named mysite.tld and will leverage DNS in order to create a subdomain drupal.mysite.tld that will have various ACLs allowing only developers to access the dynamic Drupal website.

+----------------+
| Public Website | mysite.tld @ /var/www/mysite.tld-static
+-------+--------+
        ^
        | export
        |
+-------+--------+
| Drupal Website | drupal.mysite.tld @ /var/www/mysite.tld
+----------------+

Periodically, based on a scheduler such as cron, the dynamic Drupal website will be exported to a static website in case the Drupal website is not in maintenance mode. By exporting the website only when the maintenance mode is turned off, developers can set up their own workflow and only allow the automation to exports a static version whenever the developers turn the maintenance mode off.

Preliminaries

Given a Drupal website, the Tome module has to be installed. Amongst the official instructions for Tome, a line has to be added to the Drupal configuration settings.php that will point to the filesystem directory where the dynamic Drupal website will be exported to.

Following the example, the static website is to be served from /var/www/mysite.tld-static such that the necessary configuration changes are:

$settings['tome_static_directory'] = '/var/www/mysite.tld-static';

The rest of the official setup method for Tome is to be followed, including installing the drush command-line tool via composer since drush is necessary for manipulating the website from scripts.

Setup

Two separate domains are used:

mysite.tld.        300    IN    A    X.X.X.X
drupal.mysite.tld. 300    IN    A    X.X.X.X

that expose two websites that are part of the webserver configuration using two nearly identically configured virtual hosts.

For instance, for Apache, mysite.tld, the configuration will be:

ServerName mysite.tld
 
DocumentRoot /var/www/mysite.tld-static

and for drupal.mysite.tld, respectively:

ServerName drupal.mysite.tld
 
<Location />
    Require ip 192.168.1.0/24 127.0.0.1
</Location>
 
DocumentRoot /var/www/mysite.tld

where the Location tag restricts the drupal dynamic website just to the local network (in this case 192.168.1.0/24) and the local host 127.0.0.1 - the local host is added in order to appease various website checkers that may run on the local machine.

Next, a script is placed at /etc/cron.daily/drupal-tome with the following contents:

#!/bin/bash
###########################################################################
##  Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3      ##
##  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  ##
##  rights of fair usage, the disclaimer and warranty conditions.        ##
###########################################################################
 
###########################################################################
##                            CONFIGURATION                              ##
###########################################################################
 
APACHE_USER=www-data
DRUPAL_ROOTS=( /var/www/mysite.tld )
EXPORT_SITES=( /var/www/mysite.tld-static )
DRUPAL_SITES=( https://mysiste.tld )
 
###########################################################################
##                              INTERNALS                                ##
###########################################################################
 
for i in "${!DRUPAL_ROOTS[*]}"; do
     cd "${DRUPAL_ROOTS[$i]}"
     if [ `drush state-get system.maintenance_mode` -eq 0 ]; then
         drush tome:static --uri=${DRUPAL_SITES[$i]} -y -q
         chown -R $APACHE_USER:$APACHE_USER "${EXPORT_SITES[$i]}"
     fi
done

that will use drush to:

  1. check whether the website is in maintenance mode, and,
    1. if the website is not in maintenance mode, generate the static website.
    2. set the proper permissions

Handling Static Content

The cannonical solution to serving static content such as potential directories under the web root that are independent of the site content is to create a subdomain for the content and link to it.

If the cannonical solution is not desired, then simply symlinking the directories between the dynamic website and to the static site will work.

Limitations

  • Tome and similar modules have a hard time exporting very complex websites.

drupal/separating_development_and_production_sites_with_static_exports.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1

Wizardry and Steamworks

© 2025 Wizardry and Steamworks

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.