What is php.ini?
php.ini is a file that allows you to control your PHP settings on your server. When your PHP starts, it will consult your php.ini files to see how PHP settings should be configured. So, naturally, if you make changes to the php.ini file, you may have to restart your PHP processes to see those changes go into effect.
The php.ini file can be used in many ways, some of which include:
- upload_max_filesize: Limiting the maximum file size that can be uploaded
- max_file_uploads: Limiting the maximum number of files that can be uploaded at the same time
- max_execution_time: Limiting the maximum time a script can run before it’s terminated
php.ini uses commands called “directives” to communicate with the server. You can find a list of php.ini directives on the PHP documentation site. Make sure you check the “modes” of the directives so you know they are compatible with the php.ini file. Modes are really just categories that help you figure out which directives can be used in certain PHP files. If you refer to the PHP documentation site’s list of php.ini directives, you will see that each directive has a mode associated with it. These modes are listed in the Changeable column.
Optionally, you can also group php.ini directives together into “sections.” While this does not immediately affect your PHP, it can be used to group directives together and apply them to specific hosts or paths. Check out the list of php.ini sections on the PHP documentation site.
The php.ini file has a blanket effect. How it’s configured will dictate how all your server directories are configured. However, if you want to make an exception for a directory, you would use a .user.ini file.
What is .user.ini?
.user.ini file controls the PHP settings of a single directory. It will only affect the directory it is in. However, each directory may have a user.ini file.
There are only certain directives allowed for use in a .user.ini file. The allowed directories belong to the php_ini_perdir and php_ini_user modes. Be sure to check the Changeable column of the php.ini directives list to see if the directive is usable with the .user.ini file.
One directive to keep in mind is the user_ini.filename_ttl. This directive establishes how often the .user.ini file is checked for changes. Depending on what frequency this directive is set to, changes to PHP may experience a slight delay before being implemented.