In this article we will look at how to create a development copy of your Drupal 8 website and then use the Configuration Synchronisation module to sync changes from one site to the other.
Why do this?
We have all been there, you make a simple little change to your website and it breaks. If you only have one version of your site then you have to fix it quickly before your users have their experience ruined.
This module makes it easy to experiment with a local version of your website, and then export those experiments to your production site when you are ready to take them live.
You have two (or more) versions of your website, one production site that your users see, and a development site where you can make changes and experiment without breaking things for your users.
- Make a change to your development site’s configuration (add a module, make a view etc)
- Export the configuration changes using the Configuration Synchronisation module
- Copy any files you may need such as new modules, CSS, JS files etc (more on this later)
- Paste the copied files into your production websites structure
- Import the configuration that you exported from Development
Creating the development site from your production site
The Drupal Configuration Synchronisation module only works on exact copies of a site, the site must have the same ID number (UUID) and the same or similar setup.
Do you intend for your development site to be stored on a local machine or with your web host? Your needs will dictate your setup. I will assume you have a local development site in this article.
You will need to:
- Install a web server such as Apache, along with PHP, MySQL
- Clone your Production site (files and database) to the local server
- Set up virtual hostname for your local site (optional)
Exporting and importing changes
The Configuration Synchronisation module will not sync all changes, only those made to the configuration.
It will include:
- Whether a module is installed
- Added or changed Views
- Content types and fields
What this means is that if you add a new module to your development site, then export/import the configuration to your production site, you will get an error saying the new modules cannot be installed as they don’t exist. You will have to copy the module directory from your development site and add it to your modules directory of your production site.
The same is true for CSS files and actual site content too. If you make a design change using CSS, you will have to add the CSS file to the production site yourself.
The process will go like this:
- Add new modules/content types/views/css etc to your development site
- Export the configuration (can be the complete configuration for individual items)
- Copy over any new modules and file changes to your production site
- Import the configuration changes
- Flush the cache and run the update.php as required
The above example explains the basics of how to sync, you could also consider the following:
- Add more copies of your site. A copy which is on the same server as your production site can be used to test changes in a live environment without the risk of breaking your production site. You may also want a further local copy so you can experiment.
- Git or other Version Control System. If you work with other people or simply want to keep a track of your changes, version control can make life easier.