0

I'm trying to set up two sites in EE with MSM & Master Config. But I'm failing. Feels like I'm really close but can't get over the last hurdle.

I've used this suggested method but it's not quite there.

Here are how the domains are set up (simplified):

/home/
    /site1
        /html
            /assets
                /third-party
                    /add-ons
                    /themes
                /tpl
            /config
            /system
            /themes
            /admin.php
            /index.php
    /site2
        /html
            /admin.php
            /index.php

Site1 is working fine as far as I can tell. No issues in the CP and the home page shows up fine (just has static HTML at the moment).

Site2 is another story:

  • I don't yet have templates set up for Site2 so the home page is just showing blank (expected)
  • Going to site2.dev/admin.php shows the login page but it is unstyled, which tells me it's not finding the themes folder correctly. (Same if I log in.)
  • If I'm logged into the CP via site1 and attempt to switch to site2, I get this error: Fatal error: Call to undefined method Cp::switch_site() in /path/to/home/site1/html/system/expressionengine/controllers/cp/sites.php on line 57 Update: This issue was due to having MSM be newer & not compatible with the EE version I had. Upgraded EE and no more error.

I've tried suggestion's from Jason Varga's article on this to no avail (particularly the section from "Not so fast" on, though I've tried the whole thing and that went worse).

And here's what I have in the Dynamic path settings section inside config.master.php:

$protocol                          = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
$base_url                          = $protocol . $_SERVER['HTTP_HOST'];
$base_path                         = FLC_DOCROOT;
$system_folder                     = APPPATH . '../';
$images_folder                     = 'assets/img-ee';
$images_path                       = $base_path . '/' . $images_folder;
$images_url                        = $base_url . '/' . $images_folder;

$env_config['index_page']          = '';
$env_config['site_index']          = '';
$env_config['base_url']            = $base_url . '/';
$env_config['site_url']            = $env_config['base_url'];
$env_config['cp_url']              = $env_config['base_url'] . 'admin.php';
$env_config['theme_folder_path']   = $base_path   . '/themes/';
$env_config['theme_folder_url']    = $base_url    . '/themes/';
$env_config['emoticon_path']       = $images_url  . '/smileys/';
$env_config['emoticon_url']        = $images_url  . '/smileys/';
$env_config['captcha_path']        = $images_path . '/captchas/';
$env_config['captcha_url']         = $images_url  . '/captchas/';
$env_config['avatar_path']         = $images_path . '/avatars/';
$env_config['avatar_url']          = $images_url  . '/avatars/';
$env_config['photo_path']          = $images_path . '/member_photos/';
$env_config['photo_url']           = $images_url  . '/member_photos/';
$env_config['sig_img_path']        = $images_path . '/signature_attachments/';
$env_config['sig_img_url']         = $images_url  . '/signature_attachments/';
$env_config['prv_msg_upload_path'] = $images_path . '/pm_attachments/';
$env_config['third_party_path']    = $base_path . '/assets/third-party/addons/';
$env_config['url_third_themes']    = $base_url . '/assets/third-party/themes/';
$env_config['path_third_themes']   = $base_path . '/assets/third-party/themes/';

Lastly, as far as add-ons go, most of third-party ones seem to work, but I haven't tested all of them.

So, my hunch is that something needs to change in regard to the 3rd party paths to get them to work properly and to get themes to work properly. Just not sure what. And I've no idea how to get the site switch function working in the CP to seamlessly switch from site1 to site2 and vice versa.

Any thoughts / suggestions?

1

The themes directory is usually the one challenge for the MSM and Master Config combo. There are some options, each with its own unique workaround, so you just have to choose which method seems the least cumbersome/annoying. Here are two options based on a similar directory structure.


Directory setup

/config
/system
   /codeignitor
   /expressionengine
/site1.com
   /admin   #login to CP
       /index.php   #This is the only file in this directory
   /themes
/site2.com
   /admin   #login to CP
       /index.php   #This is the only file in this directory
   /themes

NOTE: I copy the same exact themes folder for each site. This is the annoying piece I choose to live with because I have a weird thing about cross-domain linking. You just have to be careful with EE and add-on updates.

An alternative is to set a value in your config so the secondary sites know the default site's URL and path, then link to the theme files on that domain. This is what Jason Varga is doing in the "not so fast" section of link you posted. But there's an easier way, in my option. For each environment's config file, add in these four config values for that environment's URL.

config.local.php

$env_config['site1_url']        = 'http://www.site1.local';
$env_config['site1_path']       = '/local/path/to/site1.com';
$env_config['theme_folder_url']     = $env_config['site1_url'] . '/themes/';
$env_config['theme_folder_path']    = $env_config['site1_path'] . '/themes/';

config.dev.php

$env_config['site1_url']        = 'http://www.site1.dev';
$env_config['site1_path']       = '/dev/path/to/site1.com';
$env_config['theme_folder_url']     = $env_config['site1_url'] . '/themes/';
$env_config['theme_folder_path']    = $env_config['site1_path'] . '/themes/';

config.prod.php

$env_config['site1_url']        = 'http://www.site1.com';
$env_config['site1_path']       = '/prod/path/to/site1.com';
$env_config['theme_folder_url']     = $env_config['site1_url'] . '/themes/';
$env_config['theme_folder_path']    = $env_config['site1_path'] . '/themes/';

If you prefer this alternative method, then you only need the /themes directory in your default site.


For both /system/expressionengine/config/config.php and database.php you need to this:
require $_SERVER['DOCUMENT_ROOT'] . '/../config/config.master.php';


/config/config.master.php contains...

/**
     * Dynamic path settings
     * 
     * Make it easy to run the site in multiple environments and not have to switch up
     * path settings in the database after each migration
     * As inspired by Matt Weinberg: http://eeinsider.com/articles/multi-server-setup-for-ee-2/
     */
    $protocol                          = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
    $base_url                          = $protocol . $_SERVER['HTTP_HOST'];
    $base_path                         = $_SERVER['DOCUMENT_ROOT'];
    $system_folder                     = '../../system';
    $images_folder                     = 'assets/images';
    $images_path                       = $base_path . '/' . $images_folder;
    $images_url                        = $base_url . '/' . $images_folder;

    $env_config['multiple_sites_enabled']   = 'y';
    $env_config['index_page']          = '';
    $env_config['site_index']          = '';
    $env_config['base_url']            = $base_url . '/';
    $env_config['site_url']            = $env_config['base_url'];
    $env_config['cp_url']              = $env_config['base_url'] . 'admin/index.php';
    $env_config['theme_folder_path']   = $base_path   . '/themes/';
    $env_config['theme_folder_url']    = $base_url    . '/themes/';

For both sites, the /index.php, /admin.php, and /admin/index.php files share these settings, with the site_name being the only difference.

    $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
    $base_url = $protocol . $_SERVER['HTTP_HOST'] . "";
    $assign_to_config['site_name']  = 'site1'; // MSM only
    $assign_to_config['cp_url'] = $base_url . '/admin/index.php'; // masked CP access only 

Finally, define the $system_path in each of those three files for all your sites.

/index.php and /admin.php
$system_path = '../system';

/admin/index.php
$system_path = "../../system/";

  • 1
    Brilliant! This worked really well for me. Thank you! – Angie Herrera Jul 29 '14 at 16:58
1

Give this a try: https://github.com/kgrote/msm_master_config

I've been using it on a pretty complex MSM site for a while now with no issues.

  • Having a few issues. On Site1's index.php & admin.php files, I'm getting this error: Message: Undefined variable: default_site_settings Filename: ee-config/config.env.php That error is repeated for lines 15-21. There's also another error: Message: require(ee-config/db/db..php): failed to open stream: No such file or directory Filename: ee-config/config.master.php Line Number: 54 That's this line in config.master.php: require MSM_PARENT_PATH . 'ee-config/db/db.' . ENV . '.php'; I'm ignoring Site2 for now. – Angie Herrera Jul 25 '14 at 15:54
  • Gah, comment formatting. Here: gist.github.com/angieherrera/2bd95c3ccc92b7dbb7bb – Angie Herrera Jul 25 '14 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.