Co-use production content and media folder

We are going to roll out an update to a large Kirby site and we’d like to provide our client with a private link to check all change before going live. Because the content and media folders are huge, I was asking myself, if it would be possible to reuse those folders from the production site.

I’ve read about custom folder setups, see Configuring Kirby | Kirby CMS, but I don’t fully understand the way how to set this up yet.

I was thinking about a parallel folder setup on the server – /www/production and /www/dev. How would I have to set up the development version to co-use the production folders for content and media?

Are they are on the same box? You could probably symlink the content folder from live to staging, but since the media folder is always in a state of flux, i think you should probably leave that alone.

You could also use rSync to transfer from one location to another directly which might take a while the first run but subsequent runs will be much quicker since only the changes get synced. You can do this by logging into the server via SSH and doing the sync from there. And since you are using your hosting providers super fast connection to do it, it should be really fast.

Other then that, yes, you are probably looking at a custom folder setup so that both sites read from the same place. I think you actually want four folders:

/www/content/
/www/media/
/www/production/
/www/dev/

Then map the sites to read from those same content & media folders.

Yes, they are.

I’m not sure you should share the media folder. The stuff in there is auto-generated anyway.

I’m looking at a few gitabyte of data and the whole idea is about not to copy it :wink:

Okay, that’s fine. The content folder is the important one.

Symlink it :slight_smile: But be aware that changes made in dev will show up on live, since its the live content folder. rSync would be safer.

I’ve never done this. Any hits how to do this in the Kirby context?

Yes, but if we disable the panel, that should be save. The client is not touching the server.

Linux has the really neat feature of being able to link a folder to a another location. The voodoo being is that as far as the operating system is concerned, that folder exisits where the sym link is, even tho its somewhere else entirely on the server. Its just a simple command. Google for “symbolic link”, and be sure of what you are doing first, but i repeat … this is the live content content folder so any changes made in dev will show up on live.

If it was me, i would rSync it.

Other than that, you can use a custom folder setup in your index.php

<?php
include __DIR__ . '/kirby/bootstrap.php';

$kirby = new Kirby([
    'roots' => [
        'content' => 'path-to-content-folder-on-the-server'
    ]
]);

echo $kirby->render();
2 Likes

That sounds easier. How would I have to write that path though? I know __DIR__ but I need to go a folder up. Are relative notations valid? Like '../production/content'? Or is __DIR__ . '../production/content' possible?

__DIR__ . '/../www...'

This should go one up

1 Like

@nilshoerrmann If you SSH in to the box, CD into the content folder, and type pwd and hit return, it will give the full path to the folder.

… or what @texnixe just said :slight_smile:

1 Like

I’ll try this out!

This task seems to be so basic but it’s like knowing to eat with knife and fork but all I’ve got are chopsticks.
Thank you so much for your help!

1 Like

First of all, thanks @texnixe for the path solution.
It took me a while to get the development version running because of this line the in the production .htaccess which was blocking content access:

# block text files in the content folder from being accessed directly
RewriteRule ^content/(.*)\.(txt|md|mdown)$ index.php [L]

For now, I just uncommented the line but is there a way to keep the rule intact while allowing access from the development install?

Hm, I could only test this in my local environment and there I didn’t have to change anything .htaccess-wise. I always thought the rule only blocked accessing files in the content folder when trying to reach them via the browser, not programmatically on the same server. Long story short, I don’t have an answer at the moment.

Strangely, I just added the rule again and the dev site kept working. Maybe there was another issue?! I’m a bit puzzled to be honest …

A short summary how to setup things correctly. The goal is two have two parallel installs, one for production and another for development where the latter is co-using the content folder:

www/
∟ production/
  ∟ assets
  ∟ content
  ∟ kirby
  ∟ media
  ∟ site
∟ development/
  ∟ assets
  ∟ kirby
  ∟ media
  ∟ site

The only thing missing from development is the content folder.
The index.php will have to look like this:

<?php

include __DIR__ . '/kirby/bootstrap.php';

$kirby = new Kirby([
    'roots' => [
        'content' => __DIR__ . '/../production/content'
    ]
]);

echo $kirby->render();

In order to prevent content side effects, we also deactivated the panel in development/site/config.php:

<?php

return [
    'panel' => false
];

Thanks @texnixe and @jimbobrjames for guiding my way!