在 httpd.conf 中设置 PHP 变量? [英] Setting PHP variables in httpd.conf?
问题描述
我想在每个虚拟主机的基础上自动更改我的数据库连接设置,这样我就不必编辑任何 PHP 代码,因为它从登台转移到实时访问不同的数据库.这是在单个专用服务器上.
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 变量或常量作为 vhost 定义的一部分,然后站点可以使用它自动将自己指向测试数据库吗?
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
更多信息:
这篇关于在 httpd.conf 中设置 PHP 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!