PHP 可以读取/解析当前的虚拟主机' Apache VirtualHost 配置块,用于检索 ErrorLog 和 CustomLog 设置?
PHP 是否可以读取/解析当前虚拟主机的 Apache VirtualHost 配置块,特别是检索 ErrorLog 和 CustomLog 设置?
需要明确的是,我们不需要 PHP 错误日志路径,因为它很容易检索。
我在 phpinfo
或 _SERVER/getenv()
或 PHP Apache 函数 (apache_module()
, apache_note( )
, apache_getenv()
)
代码库用于多个服务器上的多个虚拟主机,因此我们无法在 PHP 中(或在 中硬编码 Apache 访问和错误日志路径) .htaccess
SetEnv
或某些 ini/csv/任何文件等),因为它可能并不总是与
中设置的内容匹配 - 操作人员可能会更新VirtualHost,但开发人员可能不会更新代码或代码用于查找相同路径的任何内容。我们不能在 CustomLog 行的下方或上方设置具有相同值的 SetEnv,因为仍然有可能在没有另一个的情况下更新一个 SetEnv(人为错误等)。
我最大的希望是 apache_getenv() ,但我尝试过 apache_getenv('CustomLog') ,但它没有返回任何内容。
运行一系列 system()/exec()
调用来运行 cli 函数来查找它们是可以的,但并不理想。
ServerName
可能与当前调用的虚拟主机不匹配,因为 ServerAlias
可能有一个包含正则表达式的不同虚拟主机,因此一旦找到 Apache conf 的路径,请手动 grep该文件不理想/不可靠。
阿帕奇 2.2.16 (Unix) PHP 5.3.3 CentOS 版本 5.5(最终版)
请告诉我我错过了一些明显的东西;)
Is it possible for PHP to read/parse the current vhosts' Apache VirtualHost config block, in particular, to retrieve ErrorLog and CustomLog settings?
To be clear we do not need the PHP error log path, that is easy to retrieve.
I couldn't find any way in phpinfo
or _SERVER/getenv()
or PHP Apache functions (apache_module()
, apache_note()
, apache_getenv()
)
The codebase is used for multiple virtual hosts on multiple servers so we can't hard code the Apache access and error log paths in PHP (or in .htaccess
SetEnv
or some ini/csv/whatever file etc), as it may not always match up with what has been set in <VirtualHost>
- someone in Operations may update the VirtualHost but a developer may not update the code or whatever the code is using to find the same path. We cannot have a SetEnv under or above the line of CustomLog with the same value, as it's still possible one will be updated without the other (human error etc.).
My best hope was apache_getenv()
but I've tried apache_getenv('CustomLog')
and it does not return anything.
Would be ok to run a series of system()/exec()
calls to run cli functions to find them, but not ideal.
The ServerName
may not match the current vhost being called, as ServerAlias
may have a different virtualhost that contains regex, so once the path to Apache conf has been found, manually grepping through the file is not ideal/reliable.
Apache 2.2.16 (Unix)
PHP 5.3.3
CentOS release 5.5 (Final)
Please tell me I've missed something obvious ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有点 hackish,但你可以放入
httpd.conf,这样你就可以使用 apache_getenv() 函数。 getenv() 不检索配置指令,只检索实际的环境变量。所以..将日志路径放入环境变量中。
It's kinda hackish, but you could put
in your httpd.conf, so you could use the apache_getenv() function. getenv() doesn't retrieve configuration directives, just actual environment variables. So.. put the log path into an environment variable.
不,你没有。 Apache 根本不会将此字符串存储在您可以访问它的任何地方。来自mod_log_config.c (请注意存储在
config_log_state
结构中的fmt
参数):您必须(无论您之前是否声明过)你不能):
修改mod_log_config.c
(坏主意!)No, you haven't. Apache simply does not store this string anyplace where you can get at it. From, mod_log_config.c (note the
fmt
argument which is stored in aconfig_log_state
struct):You must either (regardless if you've previously stated that you cannot):
Modifymod_log_config.c
(bad idea!)