Apache2 PHP: How to increase Upload File Size Limit.

After installing ownCloud on one of my servers I encountered problems regarding the default upload limit of my configuration. A php installation puts limits on upload file size. The default settings will restrict this to a max 2 MB upload file size.
The following configuration settings have to be adjusted:

upload_max_filesize - The maximum size of an uploaded file.

memory_limit - This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.

post_max_size - Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize. If memory limit is enabled by your configure script, memory_limit also affects file uploading. Generally speaking, memory_limit should be larger than post_max_size.

There are two methods two fix this problem.


Method 1: Edit the php.ini

Use a standard text editor to open /etc/php/apache2/php.ini, search for the following variables and change/increase these to:

memory_limit = 512M
upload_max_filesize = 100M
post_max_size = 100M

Some more values to change if you want a better performance of your web server:

max_execution_time = 600
max_input_time = 600
memory_limit = 1024M

Save and close the editor/file and restart the apache web server with:

service apache2 restart
or
systemctl restart apache2



Now the problem should be solved!


Method 2: Edit .htaccess

If you don't have access to the servers file system, e .g. when your site is hosted on a commercial web server, then edit (or create) the .htaccess file in your sites root.
Append/modify settings as follows:

php_value upload_max_filesize 10M
php_value post_max_size 20M
php_value memory_limit 32M

Save and close the file. These settings should now locally overrule the servers php.ini