Development and databases

Customise PHP settings with the .htaccess file

Reviewed on 3 min read PHP .htaccess

Most PHP values can be changed from the .htaccess file in public_html or in the folder where your application is. If it does not exist, create an empty file with that name.

You can also change the most common values (memory_limit, upload_max_filesize, post_max_size, max_execution_time, max_input_vars) without touching any files, from PHP in the client area or in cPanel. The .htaccess file is useful when you want a different value for just one website or folder, or when the option does not appear there.

How to do it

Add one line at the beginning of .htaccess for each value you want to change, with this syntax:

php_value directiva nuevo_valor

Where directiva is the PHP parameter and nuevo_valor is the value you want to apply. For example, to raise max_input_vars to 10000 (which PrestaShop or WooCommerce often ask for when there are many product variations):

php_value max_input_vars 10000

You can add as many lines as you need:

php_value memory_limit 512M
php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value max_execution_time 300

For options that are switched on or off (On/Off), use php_flag:

php_flag display_errors Off

The change applies immediately, without restarting anything. It applies to that folder and all its subfolders.

Check that it has been applied

In the same folder, create an info.php file with:

<?php phpinfo();

Open it in the browser (https://tudominio.com/info.php), look for the directive and check the Local Value column. Delete the file as soon as you have checked: it shows internal server data.

If you get a 500 error

If the website shows a 500 error after you add the line, remove the line: there is a typo or that website uses a PHP version that does not accept php_value in .htaccess. In that case, create a file called .user.ini in the same folder with the values in php.ini format:

max_input_vars = 10000
memory_limit = 512M

Changes in .user.ini can take up to 5 minutes to apply.

Some directives cannot be changed from a folder (for example disable_functions), and no PHP value increases your plan's resources: if you set memory_limit above the plan's memory, the plan's limit wins.

You may also find useful

Something wrong or out of date? Tell us and we will review it.