Reputation: 113
Im facing with Ubuntu PHP configuration. There is main php.ini file and directory where are stored more *.ini files.
QUESTION 1: How the PHP loading this *.ini files?
QUESTION 2: How PHP order files in ini directory? It seems alphabetically but are there other "system" than its file name?
QUESTION 3: Why Ubuntu default installation insert into additional *.ini
only loading directives extension=nameofextesion.so
and configuration of this extension leave in php.ini
? Are there any reason to split loading module and its configuration?
Example:
20-mysql.ini
contains loafing mysql extension.
extension=mysql.so
php.ini
contains mysql.*
directives. Eg.
mysql.allow_local_infile = On
mysql.allow_persistent = On
etc.
Untill now I worked with single php.ini so this is new questions for me. Thanks for any opinion or best practices.
cervenak
Upvotes: 4
Views: 4606
Reputation: 2877
The php.ini file can exist as a single php.ini file, however there are advantages to using the multiple file way.
My preference is that I enable modules using separate files located in /etc/php.d/
(this path may be different on your installation, but for the purpose of this response I will refer to it in this directory), however I also add all the configuration options in there as well as it makes it much easier to find the options this way as well.
For example I would do the following to enable opcache.
/etc/php.d/opcache.ini
zend_extension=opcache.so
opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 1024
opcache.max_accelerated_files = 65536
opcache.revalidate_freq = 3600
As for the order which it loads it, it will load the php.ini
file first, followed by the files in /etc/php.d/
in alphabetical order. If there are duplicate configurations, the ones in /etc/php.d/
will override those in php.ini
.
There are other files which can be considered as well depending on your environment and they are described in the documentation
Upvotes: 1
Reputation: 31644
In order
php.ini
is generally loaded first. Note this message in the stock php.ini
under Dynamic Extensions
; Note: packaged extension modules are now loaded via the .ini files
; found in the directory /etc/php.d; these are loaded by default.
Files are loaded alphanumerically, hence why you have 10-mysql.ini
, 20-opcache.ini
, etc
The reason for the splitting into separate configs is so you can use a package manager (i.e. apt-get, yum, etc) to install and uninstall the "extra" parts of PHP that are not core (i.e. php-mbstring
). In other words, this takes the place of having to compile PHP with your specific options turned on. The packages then install themselves into separate files that are autoloaded. If you uninstall that package, these extra configs will also be removed.
Upvotes: 6