Hi all,
Is there any “official” way of how to migrate content between different environments? For example, currently I have dev/qa/staging/prod environments, content managers created a lot of valuable content on the staging and they would like to move this content on prod/dev/qa. What is the preferred way to do it?
Actually I think about 4 options
What is the preferred way to do it?
Thanks
Our current approach is to create an env.php file in the root, which contains your base URL and database connection parameters. This file is then included in the config.php.
So my env.php might look like this:
<?php
$base_url = 'http://www.mydomain.com';
global $db;
$db['expressionengine']['hostname'] = 'localhost';
$db['expressionengine']['database'] = "mydatabase";
$db['expressionengine']['username'] = "myusername";
$db['expressionengine']['password'] = "mypassword";
and then in my config.php file, below the “ExpressionEngine Config Items” section, I put the following:
/*
|--------------------------------------------------------------------------
| Dynamic paths for cross-server compatibility
|--------------------------------------------------------------------------
*/
// Populate environment variables.
require(FCPATH . '/env.php');
$images_folder = "images";
$images_path = FCPATH . "/" . $images_folder;
$images_url = $base_url . "/" . $images_folder;
$config['index_page'] = "";
$config['base_url'] = $base_url . "/";
$config['site_url'] = $base_url;
$config['cp_url'] = $config['base_url'] . "admin.php";
$config['theme_folder_path'] = FCPATH . "/themes/";
$config['theme_folder_url'] = $base_url . "/themes/";
$config['tmpl_file_basepath'] = FCPATH . "/tmpl/";
$config['emoticon_path'] = $images_url . "/smileys/";
$config['captcha_path'] = $images_path . "/captchas/";
$config['captcha_url'] = $images_url . "/captchas/";
$config['avatar_path'] = $images_path . "/avatars/";
$config['avatar_url'] = $images_url . "/avatars/";
$config['photo_path'] = $images_path . "/member_photos/";
$config['photo_url'] = $images_url . "/member_photos/";
$config['sig_img_path'] = $images_path . "/signature_attachments/";
$config['sig_img_url'] = $images_url . "/signature_attachments/";
$config['prv_msg_upload_path'] = $images_path . "/pm_attachments/";
In my database.php, just before the first $db array definition, I’ve put an extra line:
global $db;
Keep your env.php file out of your repo, and then each environment can have its own version of this file, with their own domain/db settings.
There’s an additional consideration, which is the upload file paths. If your development environment has a different path to uploaded files than your staging or production environments, then moving your database from one environment to another may cause those file paths to be incorrect (e.g. so you’d get broken images). However, there’s a $config[‘upload_preferences’] setting that you can use to create dynamic paths in your config.php file. For example:
$config['upload_preferences'] = array(
1 => array( // ID of upload destination
'name' => 'News images',
'server_path' => '.' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'news' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR,
'url' => 'assets/news/images/'
),
2 => array( // ID of upload destination
'name' => 'Events images',
'server_path' => '.' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'events' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR,
'url' => 'assets/events/images/'
),
);
You’d need to have created the upload locations in the CMS first, and then you use the ids of those locations in the above array.
The above method is the most flexible we’ve found so far, and it works even if you’re migrating across Windows, Linux or Mac environments.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.