How to have "media" be created in public directory in public/private split setup?

Hello :waving_hand:

I’m just starting to explore setting up a site using Kirby with a public/private split and run into an issue with the media directory being created next to public instead of inside of it. I’ve set things up locally using the following tools:

  • Windows + PowerShell 7.5.2
  • PHP 8.4.11
  • ddev 1.24.7
  • composer 2.8.10
  • getkirby/cms 5.0.3

and the following steps:

mkdir my-project.com
cd my-project.com
ddev config --php-version=8.4 --omit-containers=db --docroot=public
ddev start
ddev composer create-project getkirby/starterkit my-project.com
ddev composer update
# Updated index.php following https://getkirby.com/docs/guide/configuration/custom-folder-setup#public-and-private-folder-setup
# Moved `assets/`, `media/`, `.htaccess`, `favicon.ico`, and `index.php` into `public/`

This gets me a working site and also the ability to access the panel and play around. Things are generally working.

However, one thing is broken: the media directory is being generated next to public and not inside of it. Things only worked because I manually moved media into public, but deleting both the one in public and the one next to it and then getting the media directory to be regenerated, I’m left with the one outside public. That breaks any asset retrieval including access to the panel.

Am I missing some steps for the public/private split setup (see Custom folder setup | Kirby CMS) for this to work? The documentation suggests to generally leave media alone, but that can’t be right since it has to be in the document root to be accessible by the web server.

Notes:

  • I tried the exact same setup on macOS with the same results. Though I should note that once after ddev start and loading the site, the site managed to load all assets but on the next reload, the assets were broken again.
  • I tried setting the media root to __DIR__ . '/media' in index.php manually, but that didn’t change anything. After checking dump(kirby()->roots()); this seems to be unnecessary anyway as the media root is correctly configured ([media] => /var/www/html/public/media) even without specifying it manually. Given this, I feel like what I’m seeing might be a bug.
  • The media URLs generated by kirby when accessing the site or the panel seem to be correct. Example: https://my-project.com.ddev.site/media/panel/18313f04cea0e078412a028c5361bd4e/css/style.min.css.
  • I thought briefly whether a symbolic link from public/media to media would fix this, but I develop on Windows and there are no native ways for creating symbolic links which makes this a non-starter. I also don’t think doing that would be wise in light of trying to tighten file access via the public/private split setup.
  • The site will ultimately live on a shared host and I have not yet looked into whether the public/private split setup will cause me problems there.

As an aside, the “Public folder setup” link in the Different use cases > Existing project section on Kirby meets DDEV | Kirby CMS doesn’t open the “Public folder setup” tab.

On shared hosting, the public/private setup doesn’t make sense.

It should not be necessary to set the media folder in index.php.

This I cannot reproduce

But the media directory has to be in the document root, correct? Otherwise, its assets aren’t accessible. So it would seem to be that media is not generated where index.php lives which seems like a bug to me.

Need to test this, but am currently not at my computer. Maybe it’s Window’s related

I checked that and it seems not to be the case:

I tried the exact same setup on macOS with the same results. Though I should note that once after ddev start and loading the site, the site managed to load all assets but on the next reload, the assets were broken again.

Ok, for me it works perfectly like this.

Folder setup

index.php

<?php

include __DIR__ . '/../kirby/vendor/autoload.php';

$kirby = new Kirby([
	'roots' => [
		'index'    => __DIR__,
		'base'     => $base = dirname(__DIR__),
		'content'  => $base . '/content',
		'site'     => $base . '/site',

	]
]);

echo $kirby->render();

Inside folder 503, I called

ddev config --php-version=8.3 --omit-containers=db --docroot=public
ddev start
ddev launch

After launching, the media folder was automatically created inside the public folder.

I figured it out. My update to index.php to adapt the public/private split setup was incomplete and I was still calling (new Kirby)->render instead of $kirby->render so the fix is:

  <?php

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

  $kirby = new Kirby([
    'roots' => [
      'index'    => __DIR__,
      'base'     => $base = dirname(__DIR__),
      'content'  => $base . '/content',
      'site'     => $base . '/site',
      'storage'  => $storage = $base . '/storage',
      'accounts' => $storage . '/accounts',
      'cache'    => $storage . '/cache',
      'sessions' => $storage . '/sessions',
    ]
  ]);

- echo (new Kirby)->render();
+ echo $kirby->render();