在部署一个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.

转载于:https://www.cnblogs.com/zjutzz/p/4898085.html

PHP配置,php.ini以及覆盖问题相关推荐

  1. 配置php.ini文件,关闭错误提示,打开错误日志,设置错误日志路径(亲测)

    配置php.ini文件,关闭错误提示,打开错误日志,设置错误日志路径 打开php.ini配置文件: 找到display_errors = On:修改为:display_errors = Off: 找到 ...

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

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

  3. MySQL正确配置my.ini的event_scheduler = ON

    MySQL正确配置my.ini的event_scheduler = ON 让事件的定时调度器常开,如下红框圈出部分: 永久性设置方法: 为何要在my.ini中设置: 补充mysql做一个event或j ...

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

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

  5. MySQL安装与配置my.ini

    https://www.cnblogs.com/ayyl/p/5978418.html 问题参考:https://blog.csdn.net/yulutian/article/details/7897 ...

  6. MySQL5.7配置my.ini文件

    mysql配置文件my-default.ini my.ini修改后重启无效,原来是路径错了,记录一下: windows10操作系统下: 由于我们使用MySql 时,需要修改mysql 的 my.ini ...

  7. mysql5.7免安装教程,配置my.ini详解,安装卸载mysql服务,开启远程登录,修改mysql密码

    一.下载mysql免安装版本(此文档下载版本5.7.36) 1.下载链接:https://downloads.mysql.com/archives/community/ 2.版本可按需选择:此处选择下 ...

  8. mysql 5.7.11 my.ini,mysql5.7以上版本配置my.ini的详细步骤

    Windows 64 位 mysql 5.7以上版本包解压中没有data目录和my-default.ini和my.ini文件以及服务无法启动的解决办法以及修改初始密码的方法. mysql官网下载地址 ...

  9. linux fedora配置.myBase.ini文件

    vim myBase.run 这种方式并不奏效,其实就是改了.myBase7.ini的配置内容 nullstr="" sed -i "/^App.UserLic.Exte ...

最新文章

  1. CVPR 2020 | 基于多智能体RL实现多轮连续交互,IteR-MRL使图像分割算法达到医用标准...
  2. 推荐系统中多值特征的八大处理技巧
  3. pwm控制的基本原理_最详细的电机控制说明
  4. zenmap 的扫描方式
  5. ABAP Pragma
  6. 仿Jquery链式操作的xml操作类
  7. 笨方法“学习python笔记之urlopen
  8. Flutter代码锦囊---根据环境选择URL地址
  9. 前端知识 | React Native手势响应浅析
  10. 弹出框插件——dialog
  11. springsoure.sts下载地址
  12. 初中计算机会考知识点大全,初中信息技术会考知识点复习提纲
  13. App测试之性能测试流畅度fps测试
  14. 5个免费邮箱,10分钟临时邮箱,一定能用,持续更新
  15. 【交易架构day10】阿里双十一交易核心数据及其它公司调研
  16. Few-shot transfer learning for intelligent fault diagnosis of machine(机器智能故障诊断中的小样本迁移学习)
  17. VScode如何自动换行
  18. 要求用 100 元买 100 只鸡,其中公鸡五元一只,母鸡三元一只,小鸡 1 元三只,规定每种至少买一 只
  19. 用docx把文字写入word并且插入图片、表格
  20. linux中文麻酱字_红糖麻酱卷的做法——Nice to meet you

热门文章

  1. 【CodeForces - 347C 】Alice and Bob (思维,数学,等差数列)
  2. 【HihoCoder - 1880】地铁环线 (前缀和,水题,模拟)
  3. 机器学习笔记(十六):大规模机器学习
  4. android 没有指令,android – 运行时没有命令输出:’am start -n
  5. php xml数据拼接,在PHP中合并XML文件
  6. java中js九个隐含对象_第九章 JSP标签——《跟我学Shiro》
  7. 返回地址【数据结构】
  8. C++:30 ---C++类成员,成员函数的内存布局
  9. python(16)-列表list,for循环
  10. 推荐算法--总结(08)