我刚刚从Debian Lenny升级到Squeeze,注意到我的/var/log/apache2/errors.log正在遭受以下错误的轰炸:
<b>Warning</b>: Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater in <b>Unknown</b> on line <b>0</b><br /> <br /> <b>Warning</b>: Directive 'register_globals' is deprecated in PHP 5.3 and greater in <b>Unknown</b> on line <b>0</b><br />
我觉得这很奇怪,因为这是一个系统日志和PHP(通过Apache)正试图写入HTML代码。 这似乎发生在服务器上的每个页面加载(包括任何虚拟主机)上。
将这些值设置为关是不是一个选项(我正在运行一个未维护的代码库)。 我的php.ini包含其他内容:
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED display_errors = On register_globals = On magic_quotes_gpc = On
我不知道如果这是一个错误的PHPconfiguration或Apacheconfiguration。 有谁知道我可以如何避免这些消息被写入errors.log每个页面上?
谢谢,Gardar
虽然这里的其他答案将停止错误被写入您的错误日志,他们只是忽略错误信息,而不是修复错误 。
在这种情况下的错误是,你的php.ini仍然有magic_quotes_gpc on或magic_quotes_gpc off地方。 register_globals off register_globals on或register_globals off也是如此。
错误不是指令打开或closures。 错误的是该指令不应该存在。 从php.ini中注释掉这些行或完全删除它们,PHP将停止写入有关不推荐使用的指令的错误。
当然,这可能会导致您的应用程序出现问题,如果它需要那些打开。
这是PHP 5.3中的错误的原因是,在PHP 6中,这些指令将不存在,PHP 6的行为就好像它们被设置为closures。 如果您计划升级到PHP 6,现在是开始升级或replace您的应用程序的好时机。
您可以尝试的另一个解决scheme是将PHP降级到5.2或5.1分支。
至于PHP写入Apache日志的错误,这是很自然的,因为PHP是作为Apache模块运行的。 你可以把类似error_log = /var/log/php_errors.log东西放到你的php.ini文件中,然后重新启动Apache,把PHP错误从你的Apache错误中分离出来。 当你在那里,我会build议改变display_errors off 。 错误消息通常可能包含您不希望攻击者看到的敏感信息。 你很可能会看到这写在你的php.ini:
; - display_errors = Off [Security] ; With this directive set to off, errors that occur during the execution of ; scripts will no longer be displayed as a part of the script output, and thus, ; will no longer be exposed to remote users. With some errors, the error message ; content may expose information about your script, web server, or database ; server that may be exploitable for hacking. Production sites should have this ; directive set to off.
没有理由为什么错误信息包含HTML。
要回答另一个你没有问的问题,PHP报告这个问题的原因是in <b>Unknown</b> on line <b>0</b> ,错误消息是为PHP代码行devise的,你已经写了,但它发现的错误是parsingphp.ini之前,甚至读了一行代码,甚至打开.php文件。 由于它没有打开一个文件,没有行号,所以报告为“未知”和“0”。
删除〜E_DEPRECATED
塔达姆:)
这个行为可以通过设置display_errors = Off来避免。 我对这个解决scheme并不满意,编写html格式的错误来logging文件对我来说似乎很陌生。 如果有人了解这种行为,请告诉:)