开发者

Hosting piwik on a server with a read-only filesystem

开发者 https://www.devze.com 2023-04-01 16:56 出处:网络
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 Clo

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 al开发者_高级运维so 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号