2

I use CloudControl for hosting and I would like to set up a server (possibly with load balancing support) to host piwik for all of my websites. The only problem is that the only writable directory CloudControlled allows you to access is defined by $_SERVER['TMPDIR'].

Is it possible to modify piwik to use this directory for all of its file-writing needs?

And also will I run into any issues with using load balancing? Something like automatically generated reports being generated by each node behind my load balancer since they're not aware of each other?

Kijewski
  • 25,517
  • 12
  • 101
  • 143
Casey Flynn
  • 13,654
  • 23
  • 103
  • 194
  • 1
    *Does* Piwik need write access to any files? It stores its data in a database, doesn't it? ... But if it does need write access, then you'll be doomed even if you manage to modify it, because every update will destroy your modifications. You may be better off moving to a different hosting environment in that case. – Pekka Sep 04 '11 at 20:59

2 Answers2

3

The idea is to keep this change for your system even when you update.

This is easy to do: create a bootstrap.php inside the piwik main folder.

This is the content of said file:

<?php
define('PIWIK_USER_PATH', $_SERVER['TMPDIR']);

You can double-check this: in index.php, you should see that it checks for a bootstrap.php file in the same folder. It's included when available, and this allows you to do little customizations and keep them even when you update. E.g. I've run piwik from svn for the past three years or so and have some custom changes in there.

Till
  • 22,236
  • 4
  • 59
  • 89
  • thanks for the suggestion. I've included the bootstrap.php file as you suggested but now I'm running into a new error: "The configuration file {/data/local/depsh5jzunc/tmp/config/global.ini.php} has not been found." I would assume that piwik would recognize it hasn't been installed yet and take me through the setup process if it doesn't have that config file? – Casey Flynn Sep 14 '11 at 01:07
  • Maybe add the `bootstrap.php` once it's installed? I'm guessing the `PIWIK_USER_PATH` makes it think it's setup. – Till Sep 15 '11 at 18:14
  • unfortunately then it becomes a sort of chicken-and-egg problem, as I need the boostrap.php file to force piwik to work in my only available writable folder. – Casey Flynn Sep 15 '11 at 19:52
  • Ok, in this case. I'd suggest you do the config on `localhost` before you deploy piwik. Is this possible? – Till Sep 17 '11 at 00:53
1

There's far too much code for me to be able to confirm this works, but the constant PIWIK_USER_PATH seems to be used as the base root for file io. With that in mind, editing index.php, around line 23, which is originally:

if(!defined('PIWIK_USER_PATH'))
{
    define('PIWIK_USER_PATH', PIWIK_DOCUMENT_ROOT);
}

To something like:

if(!defined('PIWIK_USER_PATH'))
{
    define('PIWIK_USER_PATH', $_SERVER['TMPDIR']);
}

Might work - but then what happens when it's trying to read a file in its original location? Since this is a temporary directory, however, it may not be viable, in which case an approach using override_function or a similar method, paired with a persistent storage (your database), might also work - by overriding file functions with a database load/save routine; obviously this opens up another can of worms of biblical proportions, thus, my final recommendation is for you to get another less restrictive host.

Filipe
  • 281
  • 1
  • 14