Configure .user.ini
Published
Updated
⚙️
Fine-tune PHP settings beyond dashboard defaults.
A .user.ini file in the root path sets PHP directives the fortrabbit dashboard does not offer, such as the timezone or session lifetimes. It works for per-directory settings only, and PHP reads changes within five minutes.
fortrabbit runs PHP with PHP-FPM, so php_value and php_flag lines in .htaccess have no effect. A .user.ini file takes their place for settings the PHP settings in the dashboard do not cover.
What .user.ini can change
PHP reads .user.ini for settings of the modes PHP_INI_PERDIR and PHP_INI_USER, see the php.ini directives list. Examples:
date.timezonedefault_charset,short_open_tagsession.*, such assession.gc_maxlifetimedisplay_errors,error_reportingmax_file_uploads
Settings of the mode PHP_INI_SYSTEM are ignored, among them opcache.*, apc.* and realpath_cache_size. Set the values the dashboard offers there: upload_max_filesize, post_max_size, max_execution_time, max_input_vars and output_buffering.
Create the file
Put .user.ini in the root path, such as public/ for Laravel or web/ for Craft CMS. It applies to the PHP scripts in that folder and below. Commit it to Git, so it deploys with the code.
; .user.ini
date.timezone = "Europe/Berlin"
session.gc_maxlifetime = 7200
session.cookie_lifetime = 7200
PHP caches the file and reads it again after up to five minutes (user_ini.cache_ttl), so a change does not show at once.
Memory
memory_limit follows the PHP plan. A higher value in .user.ini does not add memory: a PHP process that uses more than the plan holds is killed, see out of memory. Book a larger plan instead.
Check the result
phpinfo shows the active value of each setting in the "Local Value" column. A setting that keeps its old value is either of the PHP_INI_SYSTEM mode, or the file sits outside the root path, or the cache has not expired yet. A syntax error in the file makes PHP skip it.
See the PHP docs on .user.ini files.