当前位置:首页 > CN2资讯 > 正文内容

PHP配置,php.ini以及覆盖问题php.ini

13小时前CN2资讯

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

Greatness is never a given, it must be earned.
    你可能想看:

    扫描二维码推送至手机访问。

    版权声明:本文由皇冠云发布,如需转载请注明出处。

    本文链接:https://www.idchg.com/info/26503.html

    分享给朋友:

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

    如何在阿里云国际版上顺利注册与管理账户

    在数字化时代,云计算逐渐成为企业和个人不可或缺的工具。阿里云国际版(Alibaba Cloud International)便是阿里巴巴集团为全球用户推出的一项创新服务。这项服务的目标是让全球的用户,特别是非中国大陆地区的用户,能更方便地接触到高效、安全的云计算资源。 阿里云国际版的推出背景极为重要...

    搬瓦工:新手必备的VPS主机服务与瓦工实践经验分享

    1. 搬瓦工的概述 你好,今天我们来聊聊“搬瓦工”。这个名字可能对很多人来说有些陌生,但实际上它是一个由加拿大IT7 Networks公司推出的VPS主机品牌。简单来说,搬瓦工为用户提供了一种虚拟的服务器租赁服务,尤其适合那些想要搭建网站或学习Linux的新手。最吸引人的是,它的性价比非常高,价格也...

    蘑菇云:自然与核爆炸的惊人现象及其深远影响

    蘑菇云这个词,一提起来让人既熟悉又敬畏。它的外形就像个倒立的蘑菇,顶部宽大、底部则较小,这是因为它源自于强大爆炸所产生的气体。这种云朵看似平常,却是一种强烈爆炸后气体与空气混合的结果。虽然蘑菇云在现代多被与核爆炸联系在一起,但实际上,火山喷发及一些天体撞击也可能产生自然形成的蘑菇云。 了解蘑菇云的形...

    如何将800G硬盘进行有效分区

    在我们深入探讨硬盘分区之前,理解硬盘分区的概念非常重要。硬盘分区是将一个物理硬盘划分为多个独立部分的过程。每个分区就像独立的小仓库,可以用来存储不同类型的数据,比如系统文件、应用程序、甚至个人文件。当我第一次接触硬盘的时候,就被这个划分方法吸引住了。不仅能帮助我更好地管理和查找文件,还能提高系统的运...

    AWS VPS Free: 如何利用AWS Free Tier免费服务轻松构建云计算项目

    当我第一次接触AWS (亚马逊网络服务) 的时候,最吸引我的就是他们提供的各种免费的VPS服务。AWS的VPS免费服务实际上是一种叫做AWS Free Tier的计划,它允许用户在一定条件下使用AWS的多种服务而无需支付费用。这项计划的意义在于,它为刚入门的开发者和小型企业提供了一个绝佳的机会,能够...

    如何选择和管理SSL证书提升网站安全性

    在这个数字化迅速发展的时代,数据安全显得愈发重要。SSL证书(Secure Socket Layer Certificate)是一种专门设计用于保护互联网上数据传输安全的数字证书。说起SSL证书,首先,它是通过遵循SSL协议来实现的,由值得信赖的数字证书颁发机构(CA)在验证服务器身份之后签发。这样...