Kirby 3 and Composer setup problem


#1

I have installed Kirby 3 using the Composer setup, but I also want to use other php libs installed via Composer and can’t get it to Work.

My folder structure looks like this:

dev
dist
vendor
composer.json

Kirby is installed inside the dist folder using this composer.json content:

{
  "minimum-stability": "dev",
  "prefer-stable": true,
  "require": {
    "getkirby/cms": "^3.0",
    "elasticsearch/elasticsearch": "~6.0",
    "aws/aws-sdk-php": "^3.80"
  },
  "extra": {
    "kirby-cms-path": "dist/kirby"
  }
}

My Apache web server use the dist folder as root. Kirby works fine with this set up, the problem is when I try to use elasticsearch and aws which is also installed via Composer.

When trying to use:

use Elasticsearch\ClientBuilder;
$esClient = ClientBuilder::create()->setHosts($esHosts)->build();

inside my template I get the error: Class ‘Elasticsearch\ClientBuilder’ not found’.
I guess this is because the vendor folder is outside the dist folder (my web root folder)?

If I move the vendor folder inside dist the whole site breaks.
How can I change my setup to solve this?


#2

I think I solved it by start over using the plainkit Composer install.

composer create-project getkirby/plainkit dist

Now the vendor folder is inside the dist folder and it works with Elasticsearch and aws


#3

The only files and folders required inside your webserver root are:

.htaccess
index.php
/assets

Modify the index.php file be like this one:

<?php

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

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

echo $kirby->render();

The /kirby, /site and /vendor folders can stay on one level up the webserver root. That’s even more secure.

The reason it didn’t work the way you had it before was because /kirby and /vendor folders were separate.


#4

Thank you pedroborges for pointing me in the right direction. I manage to do nice Multi site config with just the asset folder, media folder, index.php and .htaccess in the public root.