PHP configuration, php. ini, and coverage issues

Source: Internet
Author: User
PHP configuration, php. ini and coverage problems when deploying a cms project to the server, because the cms template is relatively old, the php version on the server is 5.3.3 (later than 5.3, can be considered as new ), some pages display "deprecated" error messages. For security reasons, we need to suppress the error message output on the page. Therefore, we modified php. ini and found that error_reporting has been set to Off, indicating that the error is output to the log file and not displayed on the page. However, an error is displayed on the page!

Google found a solution on SO because of the overwrite of the configuration. The cms source code will overwrite the configuration of php. ini. Then modify the error_reporting statement in cms to solve the problem, for example:

if ((DEBUG_MODE & 1) == 1){    error_reporting(E_ALL & ~E_DEPRECATED);}
The following is a detailed explanation from the blog of 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 particle 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 particle 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 cocould still show, because the script won't be executed in that case.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.