grocy/public/index.php
Stefan Haller 623fce6c08
Run multi instances by making GROCY_DATAPATH customizable (#939)
Previously the data directory was fixed to the GROCY_DATAPATH constant.

This commit allows overriding the default GROCY_DATAPATH location by the
FastCGI parameter `GROCY_DATAPATH`. Relative paths are modified and get
rooted at the top level grocy installation directory.

The previous behaviour is preserved in case the new parameter is absent.

The following example nginx config snippet shows how to run multiple
instances.

```nginx
server {
    location /instance1/ {
        alias /var/www/grocy/;
        set $instance instance1;
        try_files $uri @grocy;
    }

    location /instane2/ {
        alias /var/www/grocy/;
        set $instance instance2;
        try_files $uri @grocy;
    }

    location @grocy {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME index.php;
        fastcgi_param GROCY_DATAPATH data/$instance;
    }
}
```
2020-08-18 18:10:26 +02:00

43 lines
870 B
PHP

<?php
// Definitions for embedded mode
if (file_exists(__DIR__ . '/../embedded.txt'))
{
define('GROCY_IS_EMBEDDED_INSTALL', true);
define('GROCY_DATAPATH', file_get_contents(__DIR__ . '/../embedded.txt'));
define('GROCY_USER_ID', 1);
}
else
{
define('GROCY_IS_EMBEDDED_INSTALL', false);
$datapath = 'data';
if (getenv('GROCY_DATAPATH') !== false)
{
$datapath = getenv('GROCY_DATAPATH');
}
elseif (array_key_exists('GROCY_DATAPATH', $_SERVER))
{
$datapath = $_SERVER['GROCY_DATAPATH'];
}
if ($datapath[0] != '/')
{
$datapath = __DIR__ . '/../' . $datapath;
}
define('GROCY_DATAPATH', $datapath);
}
require_once __DIR__ . '/../helpers/PrerequisiteChecker.php';
try
{
(new PrerequisiteChecker)->checkRequirements();
}
catch (ERequirementNotMet $ex)
{
die('Unable to run grocy: ' . $ex->getMessage());
}
require_once __DIR__ . '/../app.php';