Removing upload file size limitations
In order to configure a LAMP (Linux, Apache, MySQL, PHP) setup that allows a user to upload large files to their server the following has to be done:
Change the following variables in php.ini
memory_limit
= 1000M - Set memory limit to what is available on the system
post_max_size
= 4G - Ensure that this value is greater or equal to the upload_max_filesize
value
upload_max_filesize
= 4G - Set this to whatever you want the maximum to be
upload_tmp_dir:
/mnt/raid10/Files/Temp
- By default this is disabled which makes the temporary location be on the same disk as the OS is installed. In my case of running everything off of a Raspberry Pi, that makes it the SD card. To have less restriction, I set this to my network drive location instead.
After doing the above, the limitation in file upload size is the physical memory available to the device, whatever is set for memory_limit
, and the file system limitations (4GB for a FAT file structure). In the case of my Raspberry Pi 3, that was 1GB.
Bypassing the memory limit to upload a file bigger than the amount of memory available
The only way to go past the memory limit is to chunk the upload. Once chunking is enabled, what happens during an upload is the following:
- Upload initiated on webpage.
- Data from source file is streamed to the memory of webserver.
- Data is dumped from memory of webserver to temporary file location.
- Once the temporary file reaches the chunk size that was set, then that data is dumped into the final destination location file and the temp file is deleted.
- Repeat step 2 until file is completed.
How to use chunking
If you are using a download handler similar to this one (https://github.com/blueimp/jQuery-File-Upload/blob/master/server/php/UploadHandler.php) then there are many built in options available.
In my case, where the #fileupload is declared, I added a line for maxChunkSize
:
$('#fileupload').fileupload({
maxChunkSize: 10 * 1024 * 1024, // 10 MB <-----This is the line I added
add: function (e, data) {
blah blah blah
}
});
}
});
Whatever value is placed here will be the chunk size used. The size that you chose takes a little experimentation as one that is tiny will slow down the upload speed quite a bit, and one too large will result in the user of the site seeing no progress on their progress bar for quite some time. For me 10MB was a happy medium.
*Do note that the progress bar for the upload will move only when each chunk starts, so it becomes more choppy than a nice continuous progress bar but I am actually ok with this.
sudo service apache2 restart
. It may not have picked up the changes from php.ini yet. This is the only reference to an Apache specific configuration I see, but is pretty outdated.