link.png PyroCMS: Migrating a Single-Site to a Multi-Site Installation← Back

Written By: Steve Williamson

This article assumes you have already purchased a license, installed PyroCMS Professional and have a site running on it. It also assumes you are using Git for version control and deploying to production using a git repository. The article will not cover the work-flow of developing and deploying with a git repository.

Getting Started

PyroCMS Professional should be installed on a server that is accessible via the web in addition to a local development. I have found that connecting to the live database streamlines this process a bit because you do not have to worry about replicating your changes from a staging server to the production server. In order to track custom modules in version control you should update your .gitignore file to something similar to below:

.DS_Store .buildpath .project .settings .idea assets/cache/* system/cms/cache/* system/cms/config/database.php system/cms/logs/log-*.php nbproject/ uploads/* Notice the addon specific entries have been removed.

Now, the default installation of PyroCMS Professional has the following addons/ directory structure:

addons/ default/ shared_addons/ index.html The default directory is the default site's SITE_REF.

In order to create a new site go into the MSM and click "Create A New Site". Fill out the form and click Save and watch the magic happen.

Create a Site

The new addons/ directory structure should reflect the new site: addons/ default/ shared_addons/ test/ index.html

After the site is created, be sure to start tracking the new directory:

swilla@ubuntu:~/pyropro$ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # addons/test/ nothing added to commit but untracked files present (use "git add" to track) swilla@ubuntu:~/pyropro$ git add . swilla@ubuntu:~/pyropro$ git commit -a -m "Added new site" [master 20bc459] Added new site 0 files changed create mode 100644 addons/test/index.html create mode 100644 addons/test/modules/index.html create mode 100644 addons/test/themes/index.html create mode 100644 addons/test/widgets/index.html

Now that the site is created we are ready to start reconciling the addons on both sites. This is very important because if the addons conflict you will get errors. One big difference that you need to worry about is PyroCMS Professional includes the Newsletters Module and the Streams Module. If the site you are migrating used those modules make sure they are not copied to the new addons directory.

Look at the addons that exist on the site you are migrating and make sure they don't overlap with those that already exist on the PyroCMS Professional installation. If you want all sites to use the custom addons include them in the shared_addons directory. If the addons are site specific to the site that is being migrated place them in their SITE_REF addons directory. addons/test/

Once all the addons are in place on the PyroCMS Pro site you are ready to add all the files and commit them.

swilla@ubuntu:~/pyropro$ git add . swilla@ubuntu:~/pyropro$ git commit -a -m "Added new site" swilla@ubuntu:~/pyropro$ git push origin master If you are aren't using some type of automagic deploy pull your changes to the web facing version.

The next step is to copy all user generated content over to the site. Now normally I don't copy this to my development environment, so I just SCP this to the web facing server. scp -r ./uploads/default/* server@pyropro:/var/www/uploads/test/ Notice that we are copying all the files from the "default" SITE_REF to the new SITE_REF "test".

The next step is to bring the site's database over. This is the part where all the magic happens and the Migrations library kicks into gear (Thanks Phil).

It is quite possible that the site you are migrating is not running the latest version of PyroCMS, do not worry the migrations version is stored in the database so the site will be upgraded when it is first accessed on the new server.

  • The first step to migrating the database to the new site is to make an export, but before we export the database make sure you truncate the default_ci_sessions table since that tends to grow very large. Now export the database to a .sql file, you can do this with PHPmyadmin or straight from the command line. After you have the database export open it up with your favorite text editor. Remove the entries that restore the "core_*" tables. Now, since the new site uses "test_" database prefix we need to do a Find All and Replace. Search for "default_" and replace with "test_" and save the file.
  • The second step is to remove all the tables in the PyroCMS Professional database with the "test_" prefix. You can do this with PHPmyadmin, Mysql Workbench or manually through the command line.
  • The third and final step is to restore the edited backup file to the PyroCMS Pro database.

mysql -u root -p pyropro < test_back.sql

Now you are ready to access the website and the migrations should run making any schema changes needed to align the site with the latest version. Once you login to the admin section double check the version number in the footer to make sure it is in fact the latest version.

Once you have migrated all of your sites over to your MSM instance think how easy it will be creating new site not having to worry about existing content.