php.ini - Configuration Directive File

This section describes the PHP runtime configuration file, php.ini, which allows you to specify master directive values for all modules.

What Is php.ini? - php.ini is the PHP runtime configuration file, which allows you to specify master directive values for all modules.

Some PHP distribution package provides multiple versions of the configuration file. You can copy one of them and place it as php.ini in your PHP environment. For example, I have 2 version on my Windows computer:

php.ini-development   - More verbose in error messages
php.ini-production    - More secure and better performance

Since I am running PHP on a local machine to learn the PHP language, So I am taking the php.ini-development version:

>copy \php\php.ini-development \php\php.ini
        1 file(s) copied.

>type \php\php.ini | more
[PHP]

;;;;;;;;;;;;;;;;;;;
; About php.ini   ;
;;;;;;;;;;;;;;;;;;;
; PHP's initialization file, generally called php.ini, is responsible
; for configuring many of the aspects of PHP's behavior.
; ...

; Name for user-defined php.ini files. Default is ".user.ini"
;user_ini.filename = ".user.ini"

; To disable this feature set this option to empty value
;user_ini.filename =

; TTL for user-defined php.ini files (time-to-live) in seconds.
; Default is 300 seconds (5 minutes)
;user_ini.cache_ttl = 300

; Enable the PHP scripting language engine under Apache.
engine = On

; The number of significant digits displayed in floating point numbers.
precision = 14

...

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;

extension=php_bz2.dll
extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

[curl]
; A default value for the CURLOPT_CAINFO option. This is required 
; to be an absolute path.
;curl.cainfo =

[gd]
; Tell the jpeg decode to ignore warnings and try to create
; a gd image. The warning will then be displayed as notices
; disabled by default
;gd.jpeg_ignore_warning = 0

...

; End:

As you can see the php.ini file is very easy to use. The ";" character at the beginning of the line indicates a comment line. Configuration settings are provided in the format of "name = value". The default version of php.ini comes with lots of comments to help you understand what is the meaning of each setting.

For example, if I want to set a default timezone in runtime environment, I can edit php.ini and change the "date.timezone" setting:

>edit \php\php.ini

; Defines the default timezone used by the date functions
date.timezone = Europe/Paris

Now the PHP engine will be running with Europe/Paris as the default timezone.

By the way, if you are not sure where the php.ini file is located, you can find it out with the "php --ini" command. Here is an example on my macOS computer:

herong$ php --ini 

Configuration File (php.ini) Path: \php
Loaded Configuration File:         \php\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

Table of Contents

 About This Book

 Introduction and Installation of PHP

 Managing PHP Environment and Modules on macOS

 Managing PHP Environment and Modules on CentOS

Configuration and Modules

 Manage Runtime Configuration Directives

 "php -i" - Display Configuration Information

php.ini - Configuration Directive File

 Additional .ini Configuration Files

 Load PHP Extensions/Modules

 extension_dir - Module Library Location

 "php -m" - Display Loaded Modules

 get_extension_funcs() - Get Module Functions

 dl() - Load Module Dynamically

 cURL Module - Client for URL

 DOM Module - Parsing HTML Documents

 GD Module - Manipulating Images and Pictures

 MySQLi Module - Accessing MySQL Server

 OpenSSL Module - Cryptography and SSL/TLS Toolkit

 PCRE Module - Perl Compatible Regular Expressions

 SOAP Module - Creating and Calling Web Services

 SOAP Module - Server Functions and Examples

 Zip Module - Managing ZIP Archive Files

 References

 Index

 Full Version in PDF/EPUB