PHP配置,php.ini以及覆盖问题
在部署一个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以及覆盖问题的更多相关文章
- 配置php.ini实现PHP文件上传功能
本文介绍了如何配置php.ini实现PHP文件上传功能.其中涉及到php.ini配置文件中的upload_tmp_dir.upload_max_filesize.post_max_size等选项,这些 ...
- 关于PHP上传文件时配置 php.ini 中的 upload_tmp_dir
在<PHP 5.3 入门经典>9.6.3 的试一试中(P235),给出了一个上传文件的例子,这里的文件格式为jpeg图片(image/jpeg).如果之前未配置 php.ini 中的 up ...
- Python3:读取配置dbconfig.ini(含有中文)显示乱码的解决方法
Python3:读取配置dbconfig.ini(含有中文)显示乱码的解决方法 一.原因 Python 3 中虽有encoding 参数,但是对于有BOM(如Windows下用记事本指定为utf-8) ...
- WAMP3.1 安装php_redis.dll扩展并配置php.ini
一. 下载对应版本的php_redis.dll 下载地址:http://windows.php.net/downloads/pecl/releases/redis 注:php7目录下有php7.dll ...
- 绿色安装MySQL5.7版本----配置my.ini文件注意事项
前言 由于前段时间电脑重装,虽然很多软件不在C盘,但是由于很多注册表以及关联文件被删除,很多软件还需要重新配置甚至卸载重装. 使用MySQL时就遇到了这种情况,在修改配置文件无效的情况下选择了重新安装 ...
- MySQL数据库安装,配置My.ini文件
最近在做项目开发时用到了MySql数据库,在看了一些有关MySql的文章后,很快就上手使用了.在使用的过程中还是出现了一些问题,因为使用的是绿色免安装版的MySql所以在配置的时候出现了一些问题,该篇 ...
- 黄聪:php7配置php.ini使其支持<? ?>
<? ?>这种写在php配置文件里php.ini法叫short_tags,默认是不打开的,也就是,在默认配置的php里,这样写法不被认为是php脚本的,除非设置 short_open_ta ...
- win7下iis中配置php.ini文件
将php.ini-development配置文件重命名为php.ini配置文件即可. 接着做如下配置操作: 1.修改php.ini配置文件 打开php.ini配置文件,找到 12 ; On windo ...
- php性能优化二(PHP配置php.ini)
PHP优化对于PHP的优化主要是对php.ini中的相关主要参数进行合理调整和设置,以下我们就来看看php.ini中的一些对性能影响较大的参数应该如何设置. # vi /etc/PHP.ini (1) ...
随机推荐
- HDU 1556 Color the ball
这题用线段树的话简直就是一个水题..不过刚学树状数组,要用一下. 题意:每次给你a,b,表明a~b之间涂色,然后最后一次输出每个气球被涂色的次数. 要用树状数组就要考虑怎么转化为前缀和问题,这题可以这 ...
- Unity3D开发之搭建Mac OS开发环境
运行图 首先上几张图 IOS模拟器 坚屏 横屏 打包任务 摸索了一上午,才搞定在模拟器中运行.至于在Iphone真机中运行,虽然有开发者证书,目前还没在Xcode中配置好. 我今天第一次接触并使用MA ...
- Apache轻量级性能测试工具
平时工作中会需要一些性能测试,简单的性能测试完全可以由AB来替代,而不需要动用LR这样重量级的工具. 此文简单介绍一下ab的工具使用与结果分析.当作个笔记,以便以后查阅. 1.安装:要使用AB,需要先 ...
- VC2010中去掉红绝下划线
1. 在VC2010 的tools/中找到editior. 已经找到c/c++->advanced->IntelliSense->Disable IntelliSence->T ...
- RDLC系列之二 子报表
本文实现简单的子报表 一.效果图
- PyQT制作视频播放器
Python应用03 使用PyQT制作视频播放器 作者:Vamei 出处:http://www.cnblogs.com/vamei 严禁任何形式转载. 最近研究了Python的两个GUI包,Tki ...
- slatsatck file模块2种写法及系统初始化
一 . lamp搭建 file2种写法 saltstack--一键yum lamp:---请注意重点: http://www.blogs8.cn/posts/WLjId80 知识点: 文件的2种写 ...
- MySQL基础 - 外键和约束
在工作中经常会遇到不少不同的观点,比如对于数据库来说那就是是否要设置外键,设置外键的理由自然不必多说,而不设置外键的理由多半为设置外键影响性能,但就目前工作来讲,还没有涉及到因为外键而引发的数据库瓶颈 ...
- 挂多个class还是新建class —— 多用组合,少用继承
用css实现下面的效果图. 方案一 <style type="text/css"> .myList1 { border: 1px solid #333; padding ...
- iBatis.Net实现返回DataTable和DataSet对象
如题.要返回一个ADO.NET对象好像没有使用ORM的必要,而且从编程的角度看这样的实现一点也不OO,但是实际的开发场景中还是会碰到这种需求的.下面我就借鉴前人的经验,结合实际的示例,再总结一下.如果 ...