Open_basedir restriction in effect

Hi,

When using the Cookie Consent Modal plugin (Cookie Consent Modal | Kirby CMS) the JS and CSS can’t be loaded because of an exception.

is_dir(): open_basedir restriction in effect. 

File(/home/c102232/domains/theaterconcordia.nl/public_html/media/plugins/michnhokn/cookie-banner/cookie-modal.css) is not within the allowed path(s): (/home/c102232/:/tmp:/var/tmp:/opt/alt/php82/usr/share/pear/:/dev/urandom:/usr/local/lib/php/:/usr/local/php82/lib/php/)

See https://www.theaterconcordia.nl/media/plugins/michnhokn/cookie-banner/cookie-modal.css

The hosting company is saying that the error is in Filesystem/Dir.php and I should solve it there, but that is kind of ridiculous because it’s part of Kirby.

It must be some PHP configuration issue I assume, but I don’t know how to solve it. Anyone has an idea?

This is the stack trace:

Stack trace:\n#0 [internal function]: Whoops\Run->handleError()\n#1 
/home/c102232/domains/theaterconcordia.nl/public_html/.kirby/src/Filesystem/Dir.php(171): is_dir()\n#2 
/home/c102232/domains/theaterconcordia.nl/public_html/.kirby/src/Cms/PluginAssets.php(33): Kirby\Filesystem\Dir::index()\n#3 
/home/c102232/domains/theaterconcordia.nl/public_html/.kirby/src/Cms/PluginAssets.php(66): Kirby\Cms\PluginAssets::clean()\n#4 
/home/c102232/domains/theaterconcordia.nl/public_html/.kirby/config/routes.php(66): Kirby\Cms\PluginAssets::resolve()\n#5 
[internal function]: Kirby\Http\Route->{closure}()\n#6 
/home/c102232/domains/theaterconcordia.nl/public_html/.kirby/src/Http/Router.php(120): Closure->call()\n#7 /home/c102232/domains/theaterconcordia.nl/public_html/.kirby/src/Cms/App.php(341): Kirby\Http\Router->call()\n#8 
/home/c102232/domains/theaterconcordia.nl/public_html/.kirby/src/Cms/App.php(1238): Kirby\Cms\App->call()\n#9 /home/c102232/domains/theaterconcordia.nl/public_html/index.php(18): Kirby\Cms\App->render()\n#10 {main}\n

Check your php.ini file for an open_basedir setting

Ok, looks like you are using a public folder setup, without defining the root and url for your media folder. Where is that actually located?

I don’t have direct access to the php.ini, but via phpinfo() I get this:

open_basedir - local value

/home/c102232/:/tmp:/var/tmp:/opt/alt/php82/usr/share/pear/:/dev/urandom:/usr/local/lib/php/:/usr/local/php82/lib/php/

See PHP 8.2.5 - phpinfo()

Yes, public folder setup.

index.php

<?php

require '.kirby/bootstrap.php';

$kirby = new Kirby(
  [
    'roots'=> [
      'site' => __DIR__.'/site',
      'accounts' => __DIR__.'/accounts',
      'content' => __DIR__.'/content',
      'config' => __DIR__.'/config',
      'media' => __DIR__.'/media',
      'cache' => __DIR__.'/storage/cache',
      'sessions' => __DIR__.'/storage/sessions',
      'logs' => __DIR__.'/storage/logs'
    ],
  ]);

echo $kirby->render();

root listing

.kirby
accounts
assets
at
config
content
humans.txt
index.php
media
robots.txt
security.txt
site
storage

For the media folder, you also have to set the urls property, not just the root, see

Thanks for the help.
I tried this, but with the same result. :man_shrugging:

<?php

require '.kirby/bootstrap.php';

$kirby = new Kirby(
  [
    'roots'=> [
      'site' => __DIR__.'/site',
      'accounts' => __DIR__.'/accounts',
      'content' => __DIR__.'/content',
      'config' => __DIR__.'/config',
      'media' => __DIR__.'/media',
      'cache' => __DIR__.'/storage/cache',
      'sessions' => __DIR__.'/storage/sessions',
      'logs' => __DIR__.'/storage/logs'
    ],
    'urls' => [
      'index'  => 'https://www.theaterconcordia.nl',
      'media'  => 'https://www.theaterconcordia.nl/media',
      'assets' => 'https://www.theaterconcordia.nl/assets',
  ]
  ]);

echo $kirby->render();

I first had 'media' => 'https://www.theaterconcordia.nl/media/', but that resulted in a 404 error, because the path became https://www.theaterconcordia.nl/media//plugins/michnhokn/cookie-banner/cookie-modal.css with double forward slashes.

After removing the forward slash, I get the 500 error again.

The weird thing is that is only failing on that plugin (it’s the only plugin there).
The older folders below media are accessed by Kirby and have data written to, like media\pages.

I solved it in an easier way by loading the css and js myself instead of depending on the plugin.
Not ideal, but fine.