Set separate image upload-size limit for each site, with multiple sites in Trellis?

We have multiple sites with in our Trellis environment. On production (for example), we’ve set the php_upload_max_filesize and php_post_max_size variables inside group_vars/production/main.yml. This sets those values correctly on the production server, but, obviously, they then apply to every site on that server. Is there a way, using either Trellis or Bedrock, to set those variables on a per-site basis, so that, for example, the variables set inside the group_vars/production/main.yml represent a ceiling, but a given site could be set lower?

Trellis generates a single PHP-FPM config and a single pool file so it’s not easily possible to vary those per-site.

The only option I can see that might be possible is using Nginx to dynamically set the value. See Example #2 on PHP: Configuration - Manual

set $php_value "post_max_size={{ item.value.php.post_max_size }}";
set $php_value "$php_value \n upload_max_filesize={{ item.value.php.upload_max_filesize }}";
fastcgi_param  PHP_VALUE $php_value;

The above example depends on a few extra things:

  1. you’d want to define those settings as part of your wordpress_sites
wordpress_sites:
  mysite.com:
    # usual settings
    php:
      upload_max_filesize: whatever
      post_max_size: new_value
  1. create a new Nginx include file which contains that conf snippet above.

However, I’m not still 100% sure this would work since there’s a common worker pool for all sites. Maybe this just set that value for each request, but you’d have to try it out.

2 Likes