使用.htaccess可以在某种程度上更改PHP的错误显示的设置,实际上,相当于更改PHP.ini的参数,很是方便。
将以下相应代码放到对应目录中的.htaccess文件,即可实现相应功能。
关闭错误显示 :
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0
只显示PHP错误 :
php_flag display_errors on
php_flag display_startup_errors on
php_value error_reporting 2047
其中,“2047”为要显示的错误的级别,详细表格如下:
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
2047 E_ALL
2048 E_STRICT
4096 E_RECOVERABLE_ERROR
要把错误保存到日志文件中 ,可以这样设置:
# enable PHP error logging
php_flag log_errors on
php_value error_log /home/path/public_html/domain/PHP_errors.log
然后,可以设置不允许访问.log文件 :
# prevent access to PHP error log
<Files PHP_errors.log>
Order allow,deny
Deny from all
Satisfy All
</Files>
设置错误日志的最大体积 ,以bytes为单位:
# general directive for
setting max error size
log_errors_max_len integer
综合上述,.htaccess的PHP错误显示设置汇总 :
# PHP error handling for production servers
# disable display of startup errors
php_flag display_startup_errors off
# disable display of all other errors
php_flag display_errors off
# disable html markup of errors
php_flag html_errors off
# enable logging of errors
php_flag log_errors on
# disable ignoring of repeat errors
php_flag ignore_repeated_errors off
# disable ignoring of unique source errors
php_flag ignore_repeated_source off
# enable logging of php memory leaks
php_flag report_memleaks on
# preserve most recent error via php_errormsg
php_flag track_errors on
# disable formatting of error reference links
php_value docref_root 0
# disable formatting of error reference links
php_value docref_ext 0
# specify path to php error log
php_value error_log /home/path/public_html/domain/PHP_errors.log
# specify recording of all php errors
php_value error_reporting 999999999
# disable max error string length
php_value log_errors_max_len 0
# protect error log by preventing public access
<Files /home/path/public_html/domain/PHP_errors.log>
Order allow,deny
Deny from all
Satisfy All
</Files>
以下则是适合开发者应用的设置:
# PHP error handling for
development servers
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
php_value error_log /home/path/public_html/domain/PHP_errors.log
php_value error_reporting 999999999
php_value log_errors_max_len 0
<Files /home/path/public_html/domain/PHP_errors.log>
Order allow,deny
Deny from all
Satisfy All
</Files>
总之,通过.htaccess设置显示PHP错误
来控制PHP错误是否显示似乎更方便。。
分享到:
相关推荐
.htaccess 文件,全称为 Hypertext Access,是Apache服务器中的一个配置文件,用于对网站进行局部设置,以实现URL重写、访问权限控制、错误页面定制等功能。本文将深入探讨如何使用 .htaccess 在线生成器——...
首先,`.htaccess`文件主要功能在于提供一种灵活的方式去调整服务器的行为,如重定向用户、设置自定义错误页面、控制目录访问权限等。它对于那些没有直接访问服务器配置文件权限的用户尤其有用。`.htaccess`文件通常...
2. **自定义404错误页面**:使用 `ErrorDocument` 指令,可以指定当发生特定错误时显示的自定义页面。 3. **改变文件扩展名**:通过 `AddType` 和 `AddHandler` 指令,可以将文件扩展名与不同的处理器或内容类型关联...
查看文章 .htaccess怎么用2007-05-16 14:04(文章来源)http://www.dnpark.com.cn/news/mm/www/1179329504375ZKlMSgYr.html<br><br>Apache服务器的.htaccess是一个非常强大的分布式配置文件,学会使用.htaccess...
`.htaccess` 文件是 Apache 服务器配置中的一个小型文本文件,它允许你在网站的根目录或其他子目录下进行一些基本的服务器配置,如重定向、URL 重写、错误页面定制以及安全设置等,而无需修改全局的 `httpd.conf` ...
通过这种方式,当用户访问如`example.com/about`时,实际上服务器会处理`example.com/about.php`,而URL中不会显示.php扩展名。 然而,需要注意的是,这种方法仅适用于已经以.php扩展名存在的文件,并且需要服务器...
- **FastCGI 如何自定义 php.ini 文件**:讲解了 FastCGI 环境下如何使用 .htaccess 来自定义 php.ini 文件的设置。 - **.htaccess 使用要点**:总结了一些 .htaccess 使用时需要注意的关键点。 - **MediaWiki 用 ...
4、目前,我们修复了列表filelist显示逻辑错误、MIME增加功能、显示列表核心bug、网页301重定向逻辑判断; 5、解决了以前程序中显示目录列表(开关)的Bug; 6、如果发现错误问题请发邮件至406944453@qq.com或QQ:...
`.htaccess`文件主要用于实现一系列HTTP服务器的指令,如URL重写、访问控制、错误处理、防盗链设置等。在本文中,我们将深入探讨一些实用的`.htaccess`配置示例。 1. **强制添加URL末尾的反斜杠** 这个配置可以...
Apache .htaccess 文件是Web服务器配置中的一个关键元素,它允许开发者在不修改主服务器配置文件(httpd.conf)的情况下,对单个目录或子目录进行定制化设置。这篇文章主要涵盖了 .htaccess 文件的基础知识、启用...
打开`application/config.php`,找到`$config['index_page']`,将其值从`"index.php"`更改为`""`,这样设置为空字符串表示将不再显示`index.php`。 完成以上步骤后,将`.htaccess`文件放到你的CI项目根目录下,与`...
2. 错误检测:PHP可以解析htaccess文件内容,使用正则表达式检查语法错误。 3. 用户交互:PHP接收用户输入,根据输入生成或修改htaccess规则。 4. 动态生成:根据用户选择的配置选项,动态构建htaccess指令。 四、...
`.htaccess` 文件是Apache服务器配置中的一个非常重要的文件,它允许站点管理员在不修改全局服务器配置的情况下,对特定目录进行自定义设置。这篇教程总结了`.htaccess`文件的多种用途,包括权限控制、重定向、URL...
`.htaccess`文件允许你在每个目录级别自定义配置,实现诸如错误页面定制、目录保护、URL重定向、防止图片盗链等多种功能。 **自定义错误页面** 通过`.htaccess`,你可以为不同类型的HTTP错误定义自己的定制页面。...
4、目前,我们修复了列表filelist显示逻辑错误、MIME增加功能、显示列表核心bug、网页301重定向逻辑判断; 5、解决了以前程序中显示目录列表(开关)的Bug; 6、如果发现错误问题请发邮件至406944453@qq....
找到`AllowOverride`指令,并设置其值为`All`,允许`.htaccess`文件覆盖默认的配置。例如: ``` AllowOverride All ``` 修改后,别忘了重启Apache服务,以使新配置生效。你可以运行`sudo service apache2 ...
2. 使用.htaccess文件设置URL重写规则,将index2.html的请求转发到l.php。这样,当用户访问index2.html时,实际上执行的是l.php。 ```apacheconf RewriteEngine On RewriteBase / RewriteRule index2\....
七、系统初次使用无静态页,如访问静态页面出错,请进行生成或修改为动态显示即可! 八、系统中包括两套模板,goods为当前模板,请注意不要修改错误! 九、安装完毕后,请删掉到install目录
`.htaccess`文件主要用来实现URL重写、设置错误页面、限制访问等功能。以下是一些基本示例: ```apacheconf # .htaccess 文件所在目录 RewriteBase / # 打开重写引擎 RewriteEngine On # 匹配规则,这里以将.php...