How to override PHP settings
You can override most runtime php.ini values - such as memory_limit, max_execution_time and
the upload size limits - per application, without root access. To choose the PHP version or tune
PHP-FPM, see Configure PHP instead.
Before you start
-
SSH or SFTP access to the application's document root (
public_html) - see Accessing your server. -
The setting names and values you need; PHP's own documentation lists which settings may be changed at directory level.
Override per application with a .user.ini file
Create a .user.ini file in your application's document root (for example public_html) and add one
setting per line:
memory_limit = 512M
max_execution_time = 300
post_max_size = 600M
upload_max_filesize = 512M
Most settings that PHP allows to be changed at the directory level can be overridden this way.
Note
PHP re-reads .user.ini only periodically - by default about every 5 minutes - so a change is
not always instant. Allow a few minutes before you test the result.
Override for the command line
A .user.ini file applies to web requests only. For a one-off command-line run, pass the value with
-d:
php -d memory_limit=512M your-script.php
Application-specific exceptions
Some applications set their own PHP values that take precedence over .user.ini for web requests.
Magento, for example, enforces limits through a PHP_VALUE line in its generated 50main.conf
(see Custom Nginx configuration):
fastcgi_param PHP_VALUE "memory_limit=2048M \n max_execution_time=18000";
If a .user.ini change has no effect on such a site, look for an override like this first.
Verify
Confirm the value actually applied with a temporary phpinfo() page:
<?php phpinfo();
Open it in your browser, search for the setting, then delete the file - never leave a
phpinfo() page on a live site.
If it did not work
The value has not changed yet: PHP re-reads .user.ini about every five minutes, so wait and
check again. The value never changes: the file is in the wrong directory, or the application forces
its own value as Magento does above. The file must be in the document root or in the folder of the
script. Uploads that still fail with 413 are limited by the web server, not PHP - see
Fixing 403, 413 and 429 errors, or
contact support.