License in config.php and deployment

Entering a license info in config.php used to do pretty much nothing, so we didn’t have any incentive to actually do it.
Now in Kirby 2.1 a message is displayed in the Panel if you don’t enter a valid license, so you kinda have to do it, as it would not look serious if your clients saw it all the time.

I can see a few reasons why it can be an annoyance:

  • if your site’s code is public (e.g. on Github) you don’t want your license there, but still need the other options ;
  • if you have a multi-environment setup the license needs to be in multiple config files.

I did a quick test:

  • move the license option in its own file in config/license.php ;
  • include it in config.php with the code below.
$license = __DIR__ . DS . 'license.php';

if (file_exists($license)) {
  include $license;
}

And it works like a charm. You can then add the file to your .gitignore, copy it to the servers once and forget it.

But there is probably a better way?

8 Likes

Good idea :smile: and thanks for sharing, but it remains annoying if you want to deploy from that repo as well … then you have to remember to copy the license file separately …

Yes, but you may have to do it only once, not for every deployment. It depends how you manage your servers and repo though.

I do the same, with @ instead of the if:

@include __DIR__ . DS . 'license.php';

Ha, nice I didn’t know about the @ operator.
Digging a little bit, it doesn’t seem to have only fans: Five reasons why the shut-op operator (@) should be avoided

Sorry for the threadomancy :skull: Hi @Malvese , I love what you did here. Really could use that for a project I started working on, especially with other stuff like plugin keys etc. Anyway… I can’t get it to work, I think I’m not getting the $license path right in config.php, the panel can’t find the license value. Tried out a few other paths as well, not shown below. Maybe you could help me out, or any other user :v:

The folder structure:

multisites/
|__ domain-one.com/
    |__ config/
        |__ license.php
|__ domain-two.com/
    |__ config/
        |__ license.php
site/
|__ config/
    |__ config.php
site.php

The files in question:

// site.php
$kirby   = kirby();
$domain  = server::get('server_name');

$multisites = array_diff(scandir(__DIR__.'/multisites'), array('..', '.','.DS_Store'));

if (!in_array($domain, $multisites)) {
    $multisite = 'domain-one.com';
} else {
    $multisite = $domain;
}

$kirby->roots->content  = __DIR__ . DS . 'multisites' . DS . $multisite . DS . 'content';
$kirby->roots->avatars  = __DIR__ . DS . 'multisites' . DS . $multisite . DS . 'avatars';
$kirby->roots->thumbs   = __DIR__ . DS . 'multisites' . DS . $multisite . DS . 'thumbs';
$kirby->roots->accounts = __DIR__ . DS . 'multisites' . DS . $multisite . DS . 'accounts';

$kirby->urls->index   = url::scheme() . '://' . $multisite;
$kirby->urls->content = $kirby->urls->index . DS . 'multisites' . DS . $multisite . DS . 'content';
$kirby->urls->avatars = $kirby->urls->index . DS . 'multisites' . DS . $multisite . DS . 'avatars';
$kirby->urls->thumbs  = $kirby->urls->index . DS . 'multisites' . DS . $multisite . DS . 'thumbs';

// config.php
$license = __DIR__ . DS . 'multisites' . DS . $multisite . DS . 'license.php';

if (file_exists($license)) {
    include $license;
}

// license.php
c::set('license', '1234567890');

We do this in a different way. For us the license is deployed in a JSON file from our puppet system.

Then during deployment, we read the JSON file and update a placeholder in the configuration file with the license code.

echo "Installing kirby license from server file"
LICENSE=`cat ${TWOUP}/kirby-data.json | php -r "echo json_decode(file_get_contents('php://stdin'),true)['kirbyLicense'];"`
sed -i s/%license%/${LICENSE}/ site/config/license.php

Mh I haven’t tried a multisite install yet… With such a folder structure I’d try something like:

$license = __DIR__ . DS . 'multisites' . DS . $multisite  . DS . 'config'  . DS .  'license.php';

if (file_exists($license)) {
  include $license;
}

(totally untested)

The issue I see here is that you are using a variable in the config.php ($multisite) that is not known there because it is defined in the site.php…

You probably have. to get the folder name from $_SERVER_

$multisite  = server::get('server_name');

Right, although after a few tries I still can’t get the path to work. Dunno if that’s related but I accidentally also found out that a custom panel stylesheet in config.php isn’t responding either. So maybe there’s even a larger error behind the whole multi-site setup which I’m trying to figure out at the moment :face_with_monocle:

@mrunkel Your approach sounds good, although for now I’d like to keep it the “Kirby way” as I think of this structure/ setup. But maybe I’ll get back to JSON files as well.

P.S.: Thanks everyone for not blaming the threadomancy :stuck_out_tongue_winking_eye:

P.P.S.: I mean… The easiest and fastest way would be a config file for each seperate domain/ site. But… meh :slight_smile:

I would have thought it os possible to have individual config files for each. domain? Would make a. lot of sense, not only for the license files.

It is, of course. Think we’re talking about the same here.

One more thing…

I’ve been delving deeper into the multisite setup during the last days and gotta say how much I love Kirby. Haven’t been developing with K. in quite a long time but oh boy, it’s such a great framework :slight_smile: Been doing an individual config.php for each domain/ multisite as @texnixe suggested. It’s definitely the way to go IMHO. Multisite with Uniform and multiple languages, unique Google Analytics keys - all working well.

One thing though, as mentioned: I can’t get a panel stylesheet to work. I’ve tried adding it via site.php, via config.php, created assets/css/panel.css both at root level as well as in multisites, absolute and relative paths, looked into plugins and how they manage to get a panel stylesheet going… Nothing led to a result i.e. a panel stylesheet being loaded. Maybe you guys can help me out.

The folder structure:

assets/
kirby/
multisites/
|__ domain-one.com/
    |__ config/
        |__ config.php
|__ domain-two.com/
    |__ config/
        |__ config.php
panel/
site/
site.php

How to get a unique panel stylesheet for each multisite domain?

Edit: Should I start a different thread just about this topic? It’s not about license anymore.