Changing PHP settings with .htaccess

You can adjust a wide variety of PHP's default settings, with a .htaccess file.

The file is placed in the folder where you want the changes to apply. The changes apply to all files and subfolders. Note the file should be called ".htaccess" and if it does not already exist you have to create it yourself with eg. an FTP program.

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 just stand on a line in the .htaccess file. Some popular options are:

Hide error messages

php_flag display_errors off

Raise session lifetime (timeout)

php_value session.gc_maxlifetime 3600

Raise max upload size

php_value upload_max_filesize 512M
php_value post_max_size 512M

Raise max execution time

php_value max_execution_time 600

Raise max input each

php_value max_input_vars 20000

Always disable populate raw post data

php_value always_populate_raw_post_data -1

Turn off OPcache

php_flag opcache.enable off

OPcache time

php_value opcache.revalidate_freq 60

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

You can test if the changes are set correctly by looking in phpinfo(). Note this is the "Local-value" column that applies.

Article from the support category: PHP