使用.htaccess&;处理PHP错误;写入php_error.log文本文件

使用.htaccess&;处理PHP错误;写入php_error.log文本文件,php,.htaccess,error-handling,text-files,error-logging,Php,.htaccess,Error Handling,Text Files,Error Logging,用于PHP错误处理,目的是“只有管理员才能看到警告、错误等” 我应用了以下步骤: 我删除了错误报告(-1)来自myindex.php的命令 我将下面的行添加到我的.htaccess文件夹中,该文件夹就在public\u html文件夹下 我在我的public\u html文件夹中创建了error\u modes文件夹 我在error\u modes文件夹中创建了.htaccess文件 我将error\u modes文件夹的权限设置为777,可写入 我故意在footer.inc.php页面中编写。

用于PHP错误处理,目的是“只有管理员才能看到警告、错误等”

我应用了以下步骤:

  • 我删除了
    错误报告(-1)来自my
    index.php的命令
  • 我将下面的行添加到我的
    .htaccess
    文件夹中,该文件夹就在
    public\u html
    文件夹下
  • 我在我的
    public\u html
    文件夹中创建了
    error\u modes
    文件夹
  • 我在
    error\u modes
    文件夹中创建了
    .htaccess
    文件
  • 我将
    error\u modes
    文件夹的权限设置为
    777
    ,可写入
  • 我故意在
    footer.inc.php
    页面中编写
    。请注意,我没有写
    结尾的字符
  • 尽管在我的
    footer.inc.php
    页面中有故意的php语法错误,no
    php\u error.log
    文件被创建

    我在日志文件中看到了这个错误
    string
    打印在我的
    footer.inc.php
    页面中。所以php在语法错误的情况下仍能工作

    我还在下面添加了我的整个
    .htaccess
    代码。(这是在
    public\u html
    下面的一个)

    fyi:我没有访问
    php.ini
    的权限,也没有任何预设的
    .log
    文件。PHP版本是5.4

    你能纠正我吗?谢谢致以最良好的祝愿

    在public_html>.htaccess中添加了用于错误处理的命令 错误模式下的代码>.htaccess public_html>.htaccess中的完整代码
    重新编写引擎打开
    重写基/
    #始终使用www-将非www永久重定向到www
    重写cond%{HTTP_HOST}^www\。
    在上重写cond%{HTTPS}s|
    重写规则^http%1://www.%{http_HOST}%{REQUEST_URI}[R=301,L]
    #热链接保护
    重写cond%{HTTP_REFERER}^$
    重写cond%{HTTP_REFERER}^http(s)?:/(www\)?mydomain.p.ht[NC]
    重写规则\(jpg | jpeg | png | gif | css | js)$-[NC,F,L]
    #压缩文本、html、javascript、css、xml:
    AddOutputFilterByType泄气文本/普通
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE应用程序/xml
    AddOutputFilterByType DEFLATE应用程序/xhtml+xml
    AddOutputFilterByType DEFLATE应用程序/rss+xml
    AddOutputFilterByType DEFLATE应用程序/javascript
    AddOutputFilterByType DEFLATE应用程序/x-javascript
    #文件缓存是优化网站加载时间的另一种著名方法
    标题集缓存控制“最大年龄=2592000”
    #禁用目录浏览
    选项所有-索引
    #安全访问文件
    命令允许,拒绝
    全盘否定
    #安全密码文件
    命令允许,拒绝
    全盘否定
    #安全专用文件
    命令允许,拒绝
    全盘否定
    #安全专用文件
    命令允许,拒绝
    全盘否定
    #SEO友好链接
    重写规则^sitemap.xml$sitemap.php[L]
    重写规则^articles/(.+)/(.+)$index.php?page=articles&subject=1&object=2[L]
    重写规则^articles/(.+)$index.php?page=articles&subject=1[L]
    重写规则^labels/(.+)$index.php?page=labels&subject=1[L]
    重写cond%{REQUEST_FILENAME}-F
    重写cond%{REQUEST_FILENAME}-D
    重写规则^/?([^/]+)$index.php?页面=$1[L]
    #错误处理
    上的php_标志日志_错误
    php_标志显示_错误关闭
    php\u value error\u log/home/my\u user\u number/public\u html/error\u modes/php\u error.log
    php_值错误_报告-1
    
    请尝试执行以下操作:

    In.htaccess 在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
    
    
        ?>
    
    
    
    (与我合作得很好)


    希望能有所帮助。

    可能是您的文件错误。日志为只读。谢谢。我试过了。没有什么变化。我的完整路径已打印为字符串。没有创建
    log
    文件:-(/home/usernumber/public\u htmlYes,这是正确的。而且,为了以防万一,上面的.htaccess代码是针对您的public\u html/.htaccess的,而不是针对error\u modes文件夹中的.htaccess文件。此外)web中的错误日志路径区分大小写。所以请确保您检查它是否正常工作,实际上我在filezilla中更新了连接,所以我看到了错误日志文件。谢谢,比尔
    Order allow,deny
    Deny from all
    
    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
    
        # 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
    
        <?
    
        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
    
    
        ?>