设置PHP变量在httpd.conf? [英] Setting PHP variables in httpd.conf?

查看:208
本文介绍了设置PHP变量在httpd.conf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动改变对每个虚拟主机基础上我的数据库连接设置,使我没有,因为它从举办的生活,但访问不同的数据库移动到编辑任何PHP code。这是一个专用的服务器上。

I'd like to automatically change my database connection settings on a per-vhost basis, so that I don't have to edit any PHP code as it moves from staging to live and yet access different databases. This is on a single dedicated server.

所以我想,我可以设置在httpd.conf一个PHP变量或常量作为虚拟主机定义的一部分,该网站就可以使用本身指向一个测试数据库中自动?

So I was wondering, can I set a PHP variable or constant in httpd.conf as part of the vhost definition that the site can then use to point itself to a testing database automatically?

$database = 'live';
if (some staging environment variable is true) {
    $database = 'testing'; // and not live
}

如果这是不可能的,我想在这种情况下我可以放心地考察我运行上告诉主机名,但我喜欢的东西少一些脆弱

If this isn't possible, I guess in this case I can safely examine the hostname I'm running on to tell, but I'd like something a little less fragile

希望这是有道理的。

非常感谢

伊恩

推荐答案

你有没有尝试使用.htaccess文件?你可以用它覆盖的php.ini值。

Did you tried to use the .htaccess file? You could override the php.ini values using it.

只要把.htaccess文件到您的htdocs目录:

Just put the .htaccess file into your htdocs directory:

php_value name value

进一步的信息:

  • http://ca3.php.net/manual/en/configuration.changes.php
  • http://ca.php.net/manual/en/ini.php

这篇关于设置PHP变量在httpd.conf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆