Changing PHP settings with .htaccess

Edit PHP settings such as error display, upload size and timeout by adding php_flag and php_value in a .htaccess file.

You can adjust a wide range of PHP's standard settings using a .htaccess file.

The file is placed in the folder where you want the changes to apply. The changes affect all files and sub‑folders. Note that the file must be called “.htaccess” and if it does not already exist you must create it yourself, e.g. with an FTP programme.

You can see a list of all PHP settings here: http://www.php.net/manual/en/ini.list.php

The settings you want to change should simply be placed on a single line in the .htaccess file. Some popular settings are:

Hide error messages

php_flag display_errors off

Increase session lifetime (timeout)

php_value session.gc_maxlifetime 3600

Increase max upload size

php_value upload_max_filesize 512M
php_value post_max_size 512M

Increase max execution time

php_value max_execution_time 600

Increase max input vars

php_value max_input_vars 20000

Disable always populate raw post data

php_value always_populate_raw_post_data -1

Turn OPcache off

We recommend NOT turning OPcache off, as it can make your website slower.

php_flag opcache.enable off

OPcache expiry

php_value opcache.revalidate_freq 60

Some settings can also be set directly in the PHP code, using the ini_set() function. Further details about settings etc. can be found in the PHP manual: http://php.net/manual/en/ini.list.php

You can test whether the changes have been applied correctly by looking at phpinfo(). Note that the “Local‑value” column is the one that applies.

Article from the support category: PHP

Other relevant articles