Let's say I want to change the max upload limit for a Wordpress website and I give the following values:
wp-config.php: 128MB php.ini: 256MB .htaccess: 64MB
So, which one would Wordpress prioritize while processing upon need?
It's not clear from your question what you are changing in each of these files, but I presume in each case it is the upload_max_filesize
PHP setting.
In general, settings will be applied in this order, each over-riding the previous value:
ini_set()
However, this setting is defined as PHP_INI_PERDIR
, which as explained on this page means it cannot be set using ini_set
, so the wp-config.php
cannot change it. So in the example you give in the question, it will take the value from .htaccess of 64MB.
You can verify this by running echo ini_get('upload_max_filesize');
somewhere in your code.
Note that there are other places values can be set which I haven't listed above, such as per-user php.ini files, and other Apache configuration contexts. Also, some of these can be disabled, so if your server is not set to allow over-rides in .htaccess, you won't be able to set a value there either.
Also note that Wordpress includes some of its own configuration variables, which interact in different ways with the PHP configuration. For instance, WP_MEMORY_LIMIT
will attempt to raise the PHP memory_limit
setting at startup, but has code which checks and never lowers it. There's no general rule to this, it will be different for different settings.
Basically all three files are taken into consideration.
WordPress/your server will check in the following order:
wp-config.php > .htaccess > php.ini
If something on a "higher level" (later in the chain) is limiting your value, the former value will be ignored or overwritten. If a piece of the chain is missing, the value in .htaccess
for example, the next higher one will be used instead.
In your example the .htaccess
would limit the max_upload_size
to 64 MB, although your server would be fine with up to 256 MB and WordPress would also accept up to 128 MB in file size first.
You can also set a different limit via the .htaccess
file and by doing this you overwrite the value from php.ini
, so that it is no longer the dominating value. This works in a lot of hosting environments, so chances are quite good you can raise or lower the max_upload_size
in this way.
If you have a more strictly configured hosting/server, it is possible that the option to override the settings from php.ini
is disabled. In this case, overriding max_upload_size
from .htaccess
won´t work, so this could be a limiting factor.
.htaccess
is in the middle of the list, why would that one be the limiting factor?
I think flomei should edit the answer, because that is the right answer but bad explaination.
Php.ini -> .htaccess -> wp-config.php
is actually the order each file will be read and will set the values taking consideration that there is not setting previously defined.
But in the case there is a previously defined setting, this will be "over-ridden" only if the new setting is lower.
That means, if you have wp-config.php with 64Mb and .htaccess with 32 MB: wp-config.php won't override that setting because there is already a lower limit and you will end up with 32Mb.
But if you have wp-config.php with 32Mb and .htaccess with 64 MB, wp-config.php will lower the previous setting to 32Mb.
Edit: To clarify, as IMSoP points out, wp-config.php just lets you set a size that's more restrictive than what the PHP settings allow if you are changing 'WP_MEMORY_LIMIT', it doesn't let you go beyond that. So it's not actually a settings override. In fact, there are separated checks done at different points at runtime. If you are changing the php setting upload_max_filesize
as he assumes (the question doesn't indicate which settings are you changing), that has no effect.
Also, you will have to take into account that the post_max_size
must be greater than upload_max_filesize
in your php settings
upload_max_filesize
cannot be changed at runtime (presumably because it's too late for it to have any effect) so wp-config.php
can't affect it one way or the other. A built-in default of 2MB is also mentioned, and you can definitely set it higher than that.
wp-config.php
is ini_set('upload_max_filesize', '32M');
it will have no effect, ever, because that setting cannot be set at run-time as it is defined as PHP_INI_PERDIR
. (Unless that documentation page is wrong, but that seems unlikely.)
wp-config.php
values and setting arbitrary PHP values with ini_set()
. As I understand it, wp-config.php
is primarily to do with setting WordPress specific config values and many of these are indeed restricted (ie. imposed upper limit) by the underlying PHP config setting (such as WP_MEMORY_LIMIT
as mentioned in the answer). This is a WordPress thing. However, when setting arbitrary PHP config values using ini_set()
in PHP there is no such restriction.