在部署一个cms项目到服务器上的时候,因为cms的模板比较老,服务器上用的php是5.3.3版(大于5.3,可以认为是新的),有些页面会显示“deprecated”类别的错误信息。安全起见要抑制页面中的错误信息输出,于是修改php.ini,发现error_reporting已经设定为Off了,表示错误输出到日志文件而不在页面上显示。但是,页面上有显示错误啊!

Google一番后在SO上发现了解决方案,是因为配置的覆盖问题,cms源代码中会覆盖php.ini的配置。那么改动cms中的error_reporting语句就可以解决问题了,比如:

if ((DEBUG_MODE & 1) == 1)
{
error_reporting(E_ALL & ~E_DEPRECATED);
}

以下是详细的解释,来自Stefano Locati的博客

PHP Configuration, php.ini and overrides

PHP has several places where configuration can be set. While I had an idea of the precedence of those settings, I decided to test them experimentally to be sure of what I am going to say. In particular this post is focused on error_reporting, but the same considerations can hold true for any setting.

So here is a list of those places, from the more global to the more specific. Each setting lower in the list can override a setting that come before.

1. The php.ini configuration file. In case of Ubuntu there are two of them, /etc/php5/apache2/php.ini is the one used for php apache module. It will have a global effect on all virtual hosts.

2. The conf.d directory. Actually not all installations will have this modularized configuration, but in case of Ubuntu is located in /etc/php5/apache2/conf.d for the apache module. Any file added in this directory is going to be added to main php.ini configuration with higher precedence than php.ini. In other words any setting here will override settings in php.ini - I tested adding an error.ini. It will have a global effect on all vitual hosts.

3. Apache virtual host configuration. Generally set in /etc/apache2/sites-available, every virtual host can have different settings. Inside the VirtualHost tag it's possible to include "php_value error_reporting ", where value is the numeric result of the boolean operations on the constants. In this configuration, in fact is not allowed to use the mnemonic constants but only a numeric value. It will affect only a single virtual host. It will override above settings.

4. .htaccess. It's also possible to set configuration values and in particular the error_reporting setting also in .htaccess, with the same syntax described in 3. It will affect only the directory in which .htaccess is located and all subdirectories. It will override above settings, in this case is not necessary to restart apache.

5. Source code. The last place where this setting can be altered is directly in the executed PHP source. If used, will override all previous settings. It can be set calling the function "error_reporting()" or with "ini_set("error_reporting", )". Compile errors could still show, because the script won't be executed in that case.

PHP配置,php.ini以及覆盖问题的更多相关文章

  1. 配置php.ini实现PHP文件上传功能

    本文介绍了如何配置php.ini实现PHP文件上传功能.其中涉及到php.ini配置文件中的upload_tmp_dir.upload_max_filesize.post_max_size等选项,这些 ...

  2. 关于PHP上传文件时配置 php.ini 中的 upload_tmp_dir

    在<PHP 5.3 入门经典>9.6.3 的试一试中(P235),给出了一个上传文件的例子,这里的文件格式为jpeg图片(image/jpeg).如果之前未配置 php.ini 中的 up ...

  3. Python3:读取配置dbconfig.ini(含有中文)显示乱码的解决方法

    Python3:读取配置dbconfig.ini(含有中文)显示乱码的解决方法 一.原因 Python 3 中虽有encoding 参数,但是对于有BOM(如Windows下用记事本指定为utf-8) ...

  4. WAMP3.1 安装php_redis.dll扩展并配置php.ini

    一. 下载对应版本的php_redis.dll 下载地址:http://windows.php.net/downloads/pecl/releases/redis 注:php7目录下有php7.dll ...

  5. 绿色安装MySQL5.7版本----配置my.ini文件注意事项

    前言 由于前段时间电脑重装,虽然很多软件不在C盘,但是由于很多注册表以及关联文件被删除,很多软件还需要重新配置甚至卸载重装. 使用MySQL时就遇到了这种情况,在修改配置文件无效的情况下选择了重新安装 ...

  6. MySQL数据库安装,配置My.ini文件

    最近在做项目开发时用到了MySql数据库,在看了一些有关MySql的文章后,很快就上手使用了.在使用的过程中还是出现了一些问题,因为使用的是绿色免安装版的MySql所以在配置的时候出现了一些问题,该篇 ...

  7. 黄聪:php7配置php.ini使其支持<? ?>

    <? ?>这种写在php配置文件里php.ini法叫short_tags,默认是不打开的,也就是,在默认配置的php里,这样写法不被认为是php脚本的,除非设置 short_open_ta ...

  8. win7下iis中配置php.ini文件

    将php.ini-development配置文件重命名为php.ini配置文件即可. 接着做如下配置操作: 1.修改php.ini配置文件 打开php.ini配置文件,找到 12 ; On windo ...

  9. php性能优化二(PHP配置php.ini)

    PHP优化对于PHP的优化主要是对php.ini中的相关主要参数进行合理调整和设置,以下我们就来看看php.ini中的一些对性能影响较大的参数应该如何设置. # vi /etc/PHP.ini (1) ...

随机推荐

  1. mysql order by 出现Using filesort的解决办法

    http://blog.csdn.net/yangyu112654374/article/details/4251624 比如一条sql语句 select * from TABLE1 where A1 ...

  2. mobileTech

    A useful tools or tips list for mobile web application developing 这个项目收集移动端开发所需要的一些资源与小技巧 工具类网站 HTML ...

  3. 1445 送Q币

    1445 送Q币  时间限制: 1 s  空间限制: 1000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 一次在玩网络游戏的过程中,在 ...

  4. http请求过程

    想象用浏览器打开imooc.com网站,HTTP走过的环节: 1.首先,是对imooc.com域名解析,(1.1)浏览器搜索浏览器自身的DNS缓存.(DNS(Domain Name System,域名 ...

  5. 取消StringGrid的自动滚动

    StringGrid的Options的goRowSelect为false时,在点击右侧未显示完全的Cell,StringGrid会自动向左滚动,怎样设定,取消StringGrid的自动滚动啊?Delp ...

  6. C语言 const常量讲解

    //const的本质 //const本质上是伪常量,无法用于数组初始化以及全局变量初始化 //原因在于const仅仅限定变量无法直接赋值,但是却可以通过指针间接赋值 //例如局部常量在栈区,而不在静态 ...

  7. C# 杂项

    1,函数访问等级必须高于参数等级,如函数等级是PUBLIC,则参数必须高于等于PUBLIC,若为INTERNAL 则不行.INTERNAL 低于PUBLIC, 用于同一个程序集内引用,PUBLIC则可 ...

  8. 一个按钮,如果5分钟内点击再次点击给予提示操作频繁,在JS里可以这样写

    很简单. 但是,如果你要离开这个页面再进来, 就没办法限制了. 除非用cookie 储存状态 给个示例 var isLock = flase; //定义全局变量 按钮点击事件: if(isLock){ ...

  9. Listview实现不同类型的布局

    打开各种客户端发现 Listview的布局多种多样,在我以前的认知中listview不是只能放一种item布局嘛,我就震惊了,现在我自己的项目上要用到这种方式那么就去做下 原理是listview 的a ...

  10. Ubuntu 14.04 下安装google的浏览器——Chrome

    小编用过好多浏览器,但最后还是选择Chrome, 因为这款浏览器确实做的不错,可是Ubuntu下自带的是火狐,因此小编在这里和大家分享一下如何在Ubuntu下安装chrome浏览器 工具/原料   安 ...