当我已经有php.ini指令来执行似乎被忽略的操作时,如何让apache将php错误写入apache错误日志?

问题描述 投票:0回答:1

我有这样的Apache指令:

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = On
log_errors = On
log_errors_max_len = 10240
error_log = php_errors.log

我在其中一个页面上收到此错误-该错误显示在浏览器中。

Deprecated: Function money_format() is deprecated in /var/www/html/sample.php on line 152

太好了,因为它表明我的代码中有错误。但是令我惊讶的是,当我在Apache配置中明确要求不显示不赞成使用的错误时,它显示了不赞成使用的错误(~E_DEPRECATED)。

但是,无论如何...因为它是生产环境,所以我需要查看错误,但不能在浏览器中看到它。因此,我将display_errors设置为Off。但是现在,我看不到错误,尽管我的php.ini配置有执行此操作的指令,也未在任何地方记录该错误。

问题

我如何在日志中查看错误(最好是apache的error.log最好),但在浏览器中看不到。我很困惑为什么它不会以这种方式发生,因为我的php.ini指令似乎要求php通过log_errorserror_log指令来执行此操作

虚拟主机配置

<VirtualHost *:80>
    ServerName apps.domain.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/html
   <Directory /var/www/html>
       AllowOverride All
       Require all granted
   </Directory>
    Redirect permanent "/" "https://apps.domain.com/"
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =apps.domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

。htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
php apache logging configuration
1个回答
1
投票
对于这种特定情况,您不需要为apache配置进行任何编辑,但是您确实需要为php.ini编辑配置。>
// add this your php.ini file display_errors = Off error_log = /var/log/php/error.log # Assuming you have /var/log/php directory and it's writable by httpd error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

仅更改您的apache指令以执行所需的操作

您的apache配置中出了什么问题,因为您指定的路径不正确。

您需要指定绝对路径E.G/var/log/php/error.log或者您可以基于文档根目录指定路径,例如%{DOCUMENT_ROOT}/log/error.log

© www.soinside.com 2019 - 2024. All rights reserved.