在多台服务器上安装 kohana 网站

发布于 2025-01-01 01:04:22 字数 238 浏览 2 评论 0原文

我有一个 Kohana 3.0.14 网站,我想将其放在多个域上,每个域关联一个虚拟主机(不同的 ip)。

我的网站之间的区别在于配置文件和 boostrap 文件(我在其中设置要使用的语言)。

所有站点均已投入生产。

我如何“分解”网站,如何包含文件,以便我将所有 kohana 网站放在一个地方,以及每台服务器上的配置和 boostrap,以便当我修复要修复的错误时每个站点(每个域)?

多谢!

I have a Kohana 3.0.14 website that i want to put on multiple domains, having associated a virtual host each (different ips).

the difference between my websites is the configuration file and the boostrap file (where i set the language to be used).

All the sites are in production.

How can i 'breakup' the website, how can i include the files so that i would have all the kohana site in a single place, and the config and boostrap on every server, so that when i am fixing an error to be fixed on every site (every domain)?

thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弥繁 2025-01-08 01:04:22

您可以通过在 index.php 文件顶部设置环境变量来做到这一点。然后根据这个变量,您将设置配置变量、语言等。这通常是我处理登台/实时/本地环境的方式,这样做可以让您在各种安装之间保持所有代码相同。

例如,在 index.php 中:

define("ENV", "staging")

然后在 bootstrap.php 中:

$baseUrl = "http://defaultdomain.com/";
if (ENV == "staging") $baseUrl = "http://staging.somedomain.com/";

Kohana::init(array(
    'base_url'   => $baseUrl,
));

database.php 中:

if (ENV == "live") {
    $hostname = ...
    $database = ...
    $username = ...
    $password = ...
} else if (ENV == "staging") {
    $hostname = ...
    $database = ...
    $username = ...
    $password = ...
}

return array
(
    'default' => array
    (
        'type'       => 'mysql',
        'connection' => array(
            'hostname'   => $hostname,
            'database'   => $database,
            'username'   => $username,
            'password'   => $password,
            'persistent' => FALSE,
        ),
        'table_prefix' => '',
        'charset'      => 'utf8',
        'caching'      => FALSE,
        'profiling'    => TRUE,
    )

You could do that by setting up an environment variable at the top of you index.php file. Then depending on this variable, you'll set the configuration variables, languages, etc. This is usually how I handle staging/live/local environments, and doing so allows you to keep all the code identical between the various installations.

For example, in index.php:

define("ENV", "staging")

Then in bootstrap.php:

$baseUrl = "http://defaultdomain.com/";
if (ENV == "staging") $baseUrl = "http://staging.somedomain.com/";

Kohana::init(array(
    'base_url'   => $baseUrl,
));

In database.php:

if (ENV == "live") {
    $hostname = ...
    $database = ...
    $username = ...
    $password = ...
} else if (ENV == "staging") {
    $hostname = ...
    $database = ...
    $username = ...
    $password = ...
}

return array
(
    'default' => array
    (
        'type'       => 'mysql',
        'connection' => array(
            'hostname'   => $hostname,
            'database'   => $database,
            'username'   => $username,
            'password'   => $password,
            'persistent' => FALSE,
        ),
        'table_prefix' => '',
        'charset'      => 'utf8',
        'caching'      => FALSE,
        'profiling'    => TRUE,
    )
酒中人 2025-01-08 01:04:22

如果您的托管选项有限,最好的选择是选择第一个主域并使用它创建一个帐户。然后在上面放置更多的域。然后只需获取 URL 即可决定您要使用的语言等。

If your hosting options are limited, your best bet is to choose the first primary domain and create an account using that. Then park more domains on top. Then simply get the URL to decide what language etc you want to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文