Which one does WordPress prioritize when it comes to php.ini, wp-config and .htaccess?

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:

  1. php.ini
  2. Apache directives in .htaccess
  3. calls to 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.

Leave a Comment