We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Migrate content between environments

How Do I?

Eduard Trayan's avatar
Eduard Trayan
3 posts
9 years ago
Eduard Trayan's avatar Eduard Trayan

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

  1. Database migrations - create dumps of needed tables and apply this data to other servers
  2. Manually create this content again/copy-paste - but if we have a lot of content and a lot of servers it’s not an option
  3. Implement some export/import module - it will allow us to export selected entries and import it, but we need to solve issues with related images and links
  4. Use existing solutions????

What is the preferred way to do it?

Thanks

       
FountainInternet's avatar
FountainInternet
53 posts
9 years ago
FountainInternet's avatar FountainInternet

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.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.