3

I am trying to set specific server side value for virtual paths used to upload files.

All my URLs are virtual and requested are dispatched by a front controller. I have the following config in my site's only .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^ index.php [L]
</IfModule>

Since upload_max_filesize cannot be set with ini_set, I need to used either .htaccess files or Apache .conf to overrides this setting.

Considering I do not have real files/folders to put .htaccess, I presume the only way is to use Apache .conf.

I tried several ways to make it way using either <LocationMatch>, <Location> and even <FilesMatch> but cannot figure out how to make it work.

Here is how my site's vhost.conf look like:

<LocationMatch "upload">
    php_value upload_max_filesize    60M
</LocationMatch>

<Directory "/mysite/documentroot">
    DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

My theory is that since my site is using a single FrontController that that the <Location> rule is applied after the redirect, it's impossible to do this from an Apache side.

Unless I missed something, the best way to solve this would be to request a feature change on the PHP side to allow changing these settings using ini_set?

Nicolas Bouvrette
  • 211
  • 1
  • 2
  • 9
  • Try increment `post_max_size`. See http://php.net/manual/en/ini.core.php#ini.post-max-size – Federico Sierra Jun 27 '17 at 03:10
  • 1
    This is already answered in: https://stackoverflow.com/questions/1122418/changing-upload-max-filesize-on-php where it says this is one of those values that can be set in php.ini only, not from apache through mod_php. – ezra-s Jun 27 '17 at 08:38
  • 1
    @ezra-s That's not quite what that answers says. It's the shorthand notation (ie. `60M`) that can't be used outside of `php.ini`. In other contexts, the _numeric byte value_ would need to be used instead. `upload_max_filesize` certainly can be set in the Apache config. – MrWhite Jun 27 '17 at 12:02
  • Ultimately the uploaded files are presumably saved to a physical directory (eg. `upload_tmp_dir` before being moved), so shouldn't the `upload_max_filesize` restriction be imposed on the _directory_, rather than the URL through which the script is being accessed? – MrWhite Jun 27 '17 at 12:06
  • Guys, the problem has nothing to do with `post_max_size`, I'm simply trying to overwrite a PHP value using Apache's configuration simply because of how the PHP directive has been restricted. Unfortunately it seems that if an entire site redirects traffic to a front controller, there is on option for this? It works well if I add it in the `vhost.conf` itself, but since `` tags are run last, I think the URL is getting lost after the redirect. – Nicolas Bouvrette Jun 27 '17 at 16:11
  • What is the "front controller"? A load balancer? Or another virtual host in the same Apache instance? – Jesse Adelman Jul 01 '17 at 21:49
  • The front controller in this case is a single php file that takes all traffic of the virtual host. By grabbing the URL from the PHP server variables, it will be able to display the proper controller using virtual URLs (no files). Such approach can facilitate localisation and other challenges that using files can bring. – Nicolas Bouvrette Jul 01 '17 at 22:02

0 Answers0