php.ini and .user.ini: where to set a value and what applies where

For a value that suits the whole account, use the Options tab of Select PHP Version. For a value that only suits one folder, put a .user.ini file in that folder. Beyond these, try not to bother: the other routes depend on how PHP is run and, when they fail, they fail ugly.

The places a value can live

Where What it applies to When to use it
Select PHP Version, Options tab Every site on the account that uses that PHP version. The value is for everything: memory, time, upload sizes. The first place to try.
A .user.ini file The folder it sits in, and the folders inside it. Only one application needs the value, or the value is not in Options.
php_value lines in .htaccess Depends on how PHP is run. Avoid. Where they are not supported, the whole site returns a 500 error.
A php.ini of your own in a folder Do not count on it. Use .user.ini, which does the same thing and is supported.

When the same value is set in two places, the more specific one wins: the folder’s .user.ini overrides the account’s Options.

Creating a .user.ini

1 In cPanel open the File Manager, go to Settings and switch on “Show Hidden Files”. The name starts with a dot and is hidden.
2 Open the site’s (or the application’s) folder. The file must be in the folder where the script runs, or in one above it.
3 Create a file named exactly .user.ini. Not user.ini, not .user.ini.txt.
4 Write one line per value, in the form name = value. Without the word php_value. Comments start with ;.
5 Save, and wait a few minutes: PHP keeps the file in memory for a while before it reads it again.
6 Check with a file containing <?php phpinfo();. On the value’s row, the Local Value column shows what applies there and Master Value the default. Delete the file afterwards.

An example, only to show the syntax (the values are examples):

memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 120

Not everything can be changed from here. Values PHP reads only at start-up, such as the list of disabled functions or the loaded extensions, cannot be changed in a .user.ini. Extensions are switched on in the selector (switching an extension on). And a line with a typing error is silently ignored: if nothing changed, start there.
There is already a .user.ini you did not create? Security and cache plugins often leave one. Open it before replacing it: there may be a line the plugin needs.

The most requested limits have their own articles: memory exhausted, execution time and uploading large files. To see which value is really in force, viewing and adjusting your PHP configuration.

Set the value, waited, and phpinfo still shows the old one? Tell us the folder and what you wrote.

Open a support ticket

SEE ALSO

Viewing and adjusting your PHP configuration

PHP limits: memory, time, upload size and the one that fails silently

Switching a PHP extension on or off

Changing your PHP version without breaking the site

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $6.60/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?