In this blog post I detailed how easy it was to create subsites in Drupal. Subsites have the benefit of sharing the same codebase so the filesize and memory footprint on the server is much lower.
But what happens when, for whatever reason, you want to move that site away and stop it from being a subsite.
Subsites can use modules and themes from a number of directories. In the same way that a standard Drupal install may use modules and themes from the module and theme directories under sites/all and sites/default/. So too, the subsite may use modules and themes from both the all folder as well as its own subsite folder as detailed in the image.
We must therefore ensure that both shared resources (such as those taken from sites/all) and subsite only resources (sites/mysubsite in the image) are copied to the new single site. Before doing any file or database altering it is strongly advised to backup your filesystem and database!
- In your new single site directory grab the latest version of Drupal or use drush dl drupal if you have drush installed
- Ensure modules and themes from both sites/all and sites/subsite folder are moved into the sites/all directory within the new single site directory.
- Take the sites/subsite/files directory and move it to sites/adammalone/files in the new directory.
- If you have modules using libraries stored in sites/all/libraries, be sure to copy the libraries to the new single site directory.
- Move sites/subsite/settings.php to sites/default/settings.php in the new directory
This handles all changes and movements in the filesystem. Since Drupal utilises a database to store the majority of its settings we must make a couple of amendments there too.
Drupal 7 introduced the code registry whereby the location of files can be stored and only loaded when needed rather than on every page request. The system table stores filenames and other details about modules in a Drupal site, the registry table stores filenames, names of classes/interfaces and which module the class/interface belongs to, the registry_file table stores the name of the file and a hash of the file to ensure the data is up to date. Because as a subsite the database would store filenames thus:
We must ensure that the new site has the filename field altered to the new filename location for all three of the system, registry and registry_file tables. The difference in the database can be seen here.
Since going through things manually is dog work we can use a couple of SQL queries to alter everything for us.
- Connect to the database by typing mysql -uUSERNAME -pPASSWORD -DDATABASENAME or navigate to the new site directory and type drush sqlc.
- Run the following queries substituting in the correct directory:
UPDATE system SET filename = REPLACE(filename, 'sites/mysubsite/modules', 'sites/all/modules'); UPDATE registry SET filename = REPLACE(filename, 'sites/mysubsite/modules', 'sites/all/modules'); UPDATE registry_file SET filename = REPLACE(filename, 'sites/mysubsite/modules', 'sites/all/modules');
- Clear your cache with drush cc all (At this point you may need to manually clear cache tables.)
- Finally change your filesystem path(s) from sites/mysubsite/files to sites/adammalone/files.
You may need to alter some DNS or apache settings to reflect the changes but after following the above instructions there is nothing more in Drupal to be done!