Detailed explanation of PHP.ini file: The key to controlling PHP operation
PHP.ini file is the core configuration file of the PHP server. It controls various parameter settings during PHP runtime, such as upload directory, error log, maximum script execution time, and file upload size limit. After modifying this file, you need to restart the server before the changes can take effect.
php.ini file location:
The location of the php.ini file varies depending on the server and PHP installation method. You can use the phpinfo()
function to find its location.
Key settings:
This article will focus on some important php.ini settings:
engine = On
: Enable or disable the PHP engine. Setting it to Off
will completely block the execution of the PHP script. Including this item in a custom php.ini file allows for more convenient control of the PHP server.
short_open_tag = On
: Enable or disable short tags (<?
instead of <?php
). Enabling short tags is convenient, but it will affect the portability of the code, because not all servers support it. It is recommended to turn it off when developing portable code.
output_buffering = Off
: Enable or disable output buffering. When enabled, PHP will delay sending HTTP header information until the script is processed and then send it together to avoid the "headers already sent" error. But for the sake of portability of the code, it is recommended to turn it off and avoid relying on automatic output buffering.
auto_prepend_file = "header.php"
and auto_append_file = "footer.php"
: Specify files that are automatically included before and after each PHP script is executed, respectively. This is very useful for including common header and tail files, such as header.php
and footer.php
of WordPress themes.
Error handling settings:
<code>error_reporting = E_ALL|E_STRICT display_errors = Off log_errors = On error_log = "/var/log/php_errors.log"</code>
In production environment, it is recommended to set display_errors
to avoid displaying error messages directly in the browser and recording them into the specified log file (Off
). error_log
date.timezone = "US/Central"
: Set the time zone of the PHP server. This item is not set, and when the error report is enabled, the use of the date-time function will generate a warning. E_STRICT
Summary:
It is recommended that all web developers be familiar with the content of the php.ini file and personalize the configuration according to their own coding style and project needs. If using a shared hosting, the default configuration provided by the hosting provider may not be the best choice. Consult the hosting provider for custom configuration options.
FAQs:
The following are some FAQs about PHP.ini files:What is the purpose of the PHP.ini file? It is the main configuration file of PHP, which controls many runtime behaviors of PHP, including error logs, file timeouts, resource limits, and upload sizes.
How to find my PHP.ini file? You can use the phpinfo()
function to find its location.
How to modify PHP.ini file? Server file system access is required, and after modification, restarting the web server can only take effect.
What are the common PHP.ini settings? For example upload_max_filesize
, memory_limit
, max_execution_time
, etc.
Can there be multiple PHP.ini files? Yes, PHP supports multiple ini files, which can enable custom settings by project or directory.
What is the syntax of PHP.ini file? Key-value pair form, for example setting_name = value
, a comment that begins with a semicolon ;
.
How to check if PHP.ini changes take effect? Run the phpinfo()
function again to view the configuration information.
What should I do if I make an error in modifying the PHP.ini file? Permissions may be missing, please contact the hosting provider or system administrator.
Can you change the PHP.ini settings at runtime? The ini_set()
function can be used, but is limited to partial settings and is only valid in the current script.
What happens when an error occurs in the PHP.ini file? PHP may not start or set up incorrectly. Check the PHP error log to find relevant information.
(Picture description is retained)
The above is the detailed content of A Tour of PHP.INI. For more information, please follow other related articles on the PHP Chinese website!