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);}
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.

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

解讀PHP.ini檔案中關於編碼的修改方式PHP.ini檔案是PHP設定文件,可以透過修改其中的參數來配置PHP的運行環境。其中關於編碼的設定也是非常重要的,在處理中文字元、網頁編碼等方面起著重要作用。本文將詳細介紹如何在PHP.ini檔案中修改編碼相關的配置,並給予具體的程式碼範例供參考。查看目前編碼設定:在PHP.ini檔案中,可以透過搜尋以下兩個相關參數

PHP時區配置錯誤是一個常見的問題,當PHP程式碼中涉及日期和時間相關的函數時,正確配置時區是十分重要的。如果時區配置出錯,可能會導致日期時間顯示不準確或出現其他問題。解決PHP時區配置錯誤需要透過設定date_default_timezone_set()函數來指定正確的時區。下面是一個具體的程式碼範例:

在Ubuntu系統中,PHP-FPM是常用的PHPFastCGI進程管理器,用來處理PHP程式的運作。然而,在某些情況下,可能會出現PHP-FPM缺失的問題,導致PHP無法正常運作。本文將介紹如何因應Ubuntu中PHP-FPM缺失的情況,並提供具體的程式碼範例。問題描述當在Ubuntu系統中安裝PHP並啟用PHP

如何在PHP.ini中更改編碼設定,需要具體程式碼範例在PHP開發中,字元編碼是一個非常重要的問題。正確的字元編碼設定可以確保資料的正確傳輸和顯示。 PHP.ini檔案是PHP的設定文件,透過修改PHP.ini檔案我們可以進行一些全域的配置,包括字元編碼的設定。下面我們就來具體說明如何在PHP.ini檔案中更改編碼設定,並附上程式碼範例。步驟一:找到PHP.ini

MySQL是目前廣泛使用的資料庫伺服器之一,而PHP作為一種流行的伺服器端程式語言,其應用程式通常與MySQL互動。在高負載情況下,MySQL效能會受到很大影響,這時需要調整PHP配置以提高MySQL效能,進而提高應用程式的回應速度。本文將介紹如何透過PHP配置來提高MySQL效能。設定PHP.ini首先需要開啟PHP設定檔(PHP.ini),這樣可以更

Kangle伺服器環境下PHP的配置與最佳化Kangle是一款穩定、高效的伺服器軟體,許多網站都選擇在Kangle環境下運作。而PHP作為流行的伺服器端腳本語言,也常與Kangle搭配使用。本文將介紹在Kangle伺服器環境下如何設定和最佳化PHP,以提升網站的效能和安全性。一、PHP設定1.查找php.ini檔案在Kangle伺服器中,PHP的設定檔通常

如何在PHP中配置和使用MemcacheMemcache是一個常用的記憶體快取系統,可以用於加快網站的存取速度和減輕資料庫壓力。在PHP中設定和使用Memcache非常簡單,以下將介紹詳細的步驟和程式碼範例。步驟1:安裝和啟動Memcache在開始之前,首先需要在系統中安裝和啟動Memcache。可以透過以下指令在Ubuntu上進行安裝:sudoapt-get

Windows環境下配置PHP5.2.17的完整指南作為廣泛使用的網頁開發語言,PHP在Windows平台上的配置是許多開發人員面臨的挑戰之一。本文將為您提供在Windows環境下配置PHP5.2.17的詳細指南,並提供具體的程式碼範例,幫助您順利完成配置過程。首先,您需要下載PHP5.2.17的Windows版本安裝包,並將其解壓縮到您希望安裝的目錄中,下
