PHP配置,php.ini以及覆蓋問題

來源:互聯網
上載者:User
在部署一個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.

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.