Using the .user.ini file to configure PHP parameters

Web hosting 1 min read

The .user.ini file is a configuration file associated with PHP applications and scripts. This file allows users to specify custom PHP settings at the level of a particular application or directory structure, without modifying the global PHP configuration.

When using PHP-FPM (FastCGI Process Manager), .user.ini files allow you to customise PHP settings for individual web applications. The .user.ini file can help ensure that different applications have different PHP settings on the server, thereby ensuring proper operation and security.

The settings in the .user.ini files may be overridden by the default settings from the php.ini files. For example, in the .user.ini file, you can specify the values for memory_limit, max_execution_time, upload_max_filesize and other PHP settings.

To create a .user.ini file, simply create a new text file in the appropriate folder, name it .user.ini, and enter the desired settings. Don’t forget that the file’s permissions and attributes must be set correctly so that the server can read and apply the settings contained within it.

Below are some common configuration examples:

  1. memory_limit: The maximum memory limit that PHP scripts can use. For example, if you wish to limit memory usage to 256 megabytes
    memory_limit = 256M
  2. max_execution_time: The maximum execution time for PHP scripts, in seconds. For example, if you want to limit the execution time to 60 seconds:
    max_execution_time = 60
  3. upload_max_filesize: The maximum size of files that can be uploaded. For example, if you wish to set the maximum size of uploadable files to 10 megabytes:
    upload_max_filesize = 10M
  4. post_max_size: The maximum size of data uploaded using the POST method. For example, if you wish to set the maximum size of POST data to 12 megabytes:
    post_max_size = 12M
  5. display_errors: Enables or disables the display of PHP errors. If you do not want errors to appear in the browser:
    display_errors = Off
  6. error_reporting: Setting the PHP error reporting level. For example, if you only want to report critical errors and warnings:
    error_reporting = E_ERROR | E_WARNING

The full list and descriptions can be found in the official PHP documentation: https://www.php.net/manual/en/ini.list.php

Back: Web hosting articles (22)