PHP误差的.htaccess处理和写入php_error.log文本文件(PHP error ha

2019-09-01 23:14发布

对于PHP误差的目的是处理“只有管理员看到警告,错误等。”;

我申请以下步骤:

  1. 我删除error_reporting(-1); 从我的命令index.php
  2. 我下面加行到我.htaccess这是刚下public_html文件夹
  3. 我创建error_modes文件夹在我public_html文件夹
  4. 我创建.htaccess文件error_modes文件夹
  5. 我设置的权限error_modes文件夹777 ,可写的。
  6. 故意的,我写了<?php 'should see this error in log file' ?>在我footer.inc.php页。 请注意,我没有写; 字符结尾。

尽管我故意的PHP语法错误 footer.inc.php页面, 没有php_error.log创建文件!

我看到应该看到这个错误日志文件中 string ,印在我的footer.inc.php页。 所以PHP的工作,尽管语法错误!?

我还添加了我的整个.htaccess下面的代码。 (这是一个,这只是下public_html

供参考 :我没有访问php.ini ,我没有任何预先设定.log文件。 PHP的版本是5.4。

能否请您指正? 谢谢。 最好的祝福。

添加到命令的public_html> htaccess的用于错误处理

php_flag  log_errors on
php_flag display_errors off
php_value error_log  /home/my_user_number/public_html/error_modes/php_error.log
php_value error_reporting -1

在error_modes> htaccess的代码

Order allow,deny
Deny from all

在的public_html> htaccess的整个码

RewriteEngine On
RewriteBase /

#always use www - redirect non-www to www permanently
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


# hotlink protection
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.p.ht [NC]
RewriteRule \.(jpg|jpeg|png|gif|css|js)$ - [NC,F,L]

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# File caching is another famous approach in optimizing website loading time
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>

# disable directory browsing
Options All -Indexes

# secure htaccess file
<Files .htaccess>
 order allow,deny
 deny from all
</Files>

# secure password file
<Files .mypassword>
 order allow,deny
 deny from all
</Files>

# secure spesific files
<Files secret.php>
 order allow,deny
 deny from all
</Files>

# secure spesific files
<Files secret2.php>
 order allow,deny
 deny from all
</Files>

#SEO friendly linking
RewriteRule ^sitemap.xml$ sitemap.php [L]
RewriteRule ^articles/(.+)/(.+)$ index.php?page=articles&subject=$1&object=$2 [L]
RewriteRule ^articles/(.+)$ index.php?page=articles&subject=$1 [L]
RewriteRule ^labels/(.+)$ index.php?page=labels&subject=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)$ index.php?page=$1 [L]

#error handling
php_flag  log_errors on
php_flag display_errors off
php_value error_log  /home/my_user_number/public_html/error_modes/php_error.log
php_value error_reporting -1

Answer 1:

请尽量做到以下几点:

在.htaccess

    # supress php errors
    php_flag display_startup_errors off
    php_flag display_errors off
    php_value docref_root 0
    php_value docref_ext 0


    # enable PHP error logging
    php_flag  log_errors on
    php_value error_log  /correct_path_to_your_website/error_modes/PHP_errors.log


    # general directive for setting php error level
    php_value error_reporting -1

在PHP文件

而不是你故意的错误在你的PHP文件中写道:你可以尝试做这样的事情:

    <?

    echo $_SERVER['DOCUMENT_ROOT']; // this will enable you to see 
                                    // the correct path to your website dir 
                                    // which should be written in .htaccess 
                                    // instead of correct_path_to_your_website
                                    // (check it just in case)

    $foo = $bar['nope'];// this should generate notice 

    call_undefined(); // this should generate fatal error


    ?>

良好的工作与我)

希望能对大家有所帮助。



文章来源: PHP error handling with .htaccess & writing into php_error.log text file