在部署一个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. React 之 Hello world

    一入react深似海,从此学习为常态,react 成为了一种趋势,很多人应该很多人准备进坑,下面对react进行简单的描述: 首先学习react,要有多方学习的准备,例如:Webpack, Babel ...

  2. NGUI OnChange Event

    那些组件有OnChange? 下面这些组件都有OnChange事件,当你点击,下拉选择时,就会触发它们. NGUI中对应的组件 PopupList (下拉列表) Toggle (复选框) Input ...

  3. Python-面向对象编程

    概述: 面向过程:根据业务逻辑从上到下写代码. 函数式:将某功能代码封装到函数中,以后便无需重复编写,进调用函数即可. 面向对象:对函数进行分类和封装,让开发“更快更好更强” 创建类和对象 面向对象编 ...

  4. EasyUI概述

    EasyUI是基于jQuery的一套UI框架,主要应用场景是后台管理系统的UI开发. 其提供了以下几个模块的插件 1.布局 2.菜单与按钮 3.表单 4.窗口 可以让开发人员,特别是后端开发人员,在不 ...

  5. ABP入门系列——使用ABP集成的邮件系统发送邮件

    ABP中对邮件的封装主要集成在Abp.Net.Mail和Abp.Net.Mail.Smtp命名空间下,相应源码在此. #一.Abp集成的邮件模块是如何实现的 分析可以看出主要由以下几个核心类组成: E ...

  6. JS原生父子页面操作

    var api = frameElement.api;  //当前 W = api.opener;//父页面 W.setPerSel(jsonStr); api.close(); //关闭窗口 js操 ...

  7. iOS技巧,宏定义

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAnoAAAPCCAYAAADvRHWgAAAAAXNSR0IArs4c6QAAAZ1pVFh0WE1MOm

  8. 备份U盘分区表,未雨绸缪

    有时候,由于操作不当将U盘或者移动硬盘插入到电脑的时候会变成RAW格式,不可读取,这样的话就杯具了,只能用恢复软件试试看. 但是,如果一开始进行了备份的话,处理起来就简单多了. 用winhex打开U盘 ...

  9. 20145215实验三 敏捷开发与XP实践

    20145215实验三 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 实验步骤 (一)敏捷开发与XP 软件工程是把系统的.有序的.可量化的方法应用到软件的开发.运营和维护上的过程.软 ...

  10. php模式设计之 适配器模式

    在这个有没有对象都要高呼“面向对象”的年代,掌握面向对象会给我们带来意想不到的方便.学编程的小伙伴从开始能写几行代码实现简单功能到后来懂得将一些重复的操作组合起来形成一个“函数”,再到后来将“函数”和 ...