Note: You are currently viewing documentation for Moodle 3.7. Up-to-date documentation for the latest stable version of Moodle may be available here: File upload size.

File upload size: Difference between revisions

From MoodleDocs
(33 intermediate revisions by 8 users not shown)
Line 1: Line 1:
Probably the most frequently asked question in the Moodle.org Using Moodle forums is "How do I increase the upload file size limit?" The changes that need be made are the same in all versions of Moodle, just in different OS' they need be made in different places. Upload file sizes are restricted in a number of ways and each one in this list restricts the following ones:
{{Installing Moodle}}
==Upload file size restrictions==


Server level
Probably the most frequently asked question on moodle.org is "How do I increase the upload file size limit?" The changes that need be made are the same in all versions of Moodle, just in different OS' they need be made in different places. Upload file sizes are restricted in a number of ways and each one in this list restricts the following ones:
Moodle site level
 
Course level
# Server level
Activity level
# Moodle site level
# Course level
# Activity level


This is a contentious issue, mainly because you might think that it should be set inside the Moodle. Unfortunately, this is not so, these are environment issues that need to be set in the server and PHP folders, Moodle cannot work outside itself.  
This is a contentious issue, mainly because you might think that it should be set inside the Moodle. Unfortunately, this is not so, these are environment issues that need to be set in the server and PHP folders, Moodle cannot work outside itself.  
Line 14: Line 17:


==Restricting the File size - how it works==
==Restricting the File size - how it works==
The Host may set a limit on the maximum file upload size in the Server environment, which you may override if the Host allows you to. PHP has a limit that it uses to limit the size of the file that it handles in upload. The Host has set that figure in the php.ini based on their particular perceptions and their clientele need. This size appears in Moodle in the '''Administration > Security > Site Policies > Maximum uploaded file size''' drop-down combo box. You can change this at any time to suit your site need. In the Course Settings page, there is also a further restriction that can be made. At no time can the Course setting over-ride the Site setting, nor can the Site setting over-ride the php.ini setting, which cannot over-ride the Server setting. The only exception to this rule is that you can manipulate both the Server and the PHP settings, and how to do that is described below.  
The Host may set a limit on the maximum file upload size in the Server environment, which you may override if the Host allows you to. PHP has a setting that it uses to limit the size of the file that it handles in upload. The Host has set that figure in the php.ini based on their particular perceptions and their clientele need. This size appears in Moodle in the '''Site administration > Security > Site security settings > Maximum uploaded file size''' drop-down combo box. You can change this at any time to suit your site need. In the Course Settings page, there is also a further restriction that can be made. At no time can the Course setting over-ride the Site setting, nor can the Site setting over-ride the php.ini setting, which cannot over-ride the Server setting. The only exception to this rule is that you can manipulate both the Server and the PHP settings, and how to do that is described below.


==Modifying the php.ini file==
==Modifying the php.ini file==
These instructions show you how to change the file upload size by editing your php.ini file.
These instructions show you how to change the file upload size by editing your php.ini file.
For the most part these instructions amount to the following.
In the file /etc/php5/apache2/php.ini you need to change "post_max_size", "upload_max_filesize" and "max_execution_time" to values that suit your needs using whatever editor you are used to.
Below are some line by line instructions for various installations of Moodle.
====Ubuntu Linux Instructions====
====Ubuntu Linux Instructions====


These instructions assume that you have installed the standard Moodle package, PHP 5 and Apache 2 via apt-get and left it all as a default install. If you have compiled yourself I presume that you will know where your php.ini files are!
These instructions assume that you have installed the standard Moodle package, PHP 5 and Apache 2 via apt-get and left it all as a default install. If you have compiled yourself I presume that you will know where your php.ini files are!
NB As latest version of '''PHP is now 7.2+''' you may need to find the file.  If you run phpinfo() this should give you the correct location which will be something like:  /etc/php/7.3/apache2/php.ini


You need to edit the following three settings in your php.ini file located at: /etc/php5/apache2/
You need to edit the following three settings in your php.ini file located at: /etc/php5/apache2/
Here are a set of instructions to follow line by line.


*Type "sudo nano /etc/php5/apache2/php.ini"
*Type "sudo nano /etc/php5/apache2/php.ini"
Line 33: Line 44:
*Press Ctrl and O
*Press Ctrl and O
*Press Ctrl and X
*Press Ctrl and X
*Type sudo /etc/init.d/apache2 restart
*Type sudo apachectl restart
 
 
 
[http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size NGINX] system administrators should also add "client_max_body_size XXXm;" to the "http" section of their nginx main configuration file. ([https://rtcamp.com/tutorials/php/increase-file-upload-size-limit/#change-in-nginx-config see more info]) if you have SSL, that will require you to set the above for the SSL ''server'' and ''location'' too.


Your new file size limit should now appear in Administration > Security > Site Policies > Maximum uploaded file size
Your new file size limit should now appear in Administration > Security > Site Policies > Maximum uploaded file size
====XAMPP on Mac Instructions====
These are instructions for how to do this for Moodle on a Mac using the [http://download.moodle.org/macosx/ XAMPP sample download package available]. (This is not for a OS X production server.)
* Close down Apache and MySQL if they are running via the XAMPP Control app and close the XAMPP Control app
* Open Finder and go to Applications
* Navigate down and open the folder ''XAMPP'' / ''xamppfiles'' / ''etc''
* Open the file ''php.ini'' with TextEdit (or another plain text editor)
* Search for the ''post_max_size'' setting and up this from 128M (the default) to more; 500M is the maximum
* Do the same for ''upload_max_filesize'' (make the numbers the same)
* Search for the ''max_execution_time'' setting and up this to 300 (or more if you get timeouts on uploads)
* Save the php.ini file
* restart Apache and MySQL as usual
Note: You may get a "permission denied" error when saving the php.ini file unless you are logged in with  admin access to your Mac. To work around this, you can set the ''/etc'' directory in which the php.ini file is located to be writable temporarily. For how to do that, see [http://answers.yahoo.com/question/index?qid=20090115235753AA4DtJ0 here] or [http://www.ehow.com/how_2314896_fix-permissions-mac-os-x.html here].


====Windows XP and Server 2003 Instructions====
====Windows XP and Server 2003 Instructions====
Line 70: Line 102:
'''NOTE:''' These instructions also cover the Xampp Windows installer. Just replace C:\PHP with C:\Moodle\server\php and to restart your Moodle with a normal stop-start.
'''NOTE:''' These instructions also cover the Xampp Windows installer. Just replace C:\PHP with C:\Moodle\server\php and to restart your Moodle with a normal stop-start.


===Modifying the apache config file===
==Modifying the apache config file==
====Ubuntu Linux Instructions====
====Ubuntu Linux Instructions====
You may also need to edit the config.php file in the moodle directory:
You may also need to edit the config.php file in the moodle directory:
Line 85: Line 117:
*Type sudo /etc/init.d/apache2 restart
*Type sudo /etc/init.d/apache2 restart


===Modifying the .htaccess file===
The following instructions will only work on an Apache web server, and also the Apache server must have Overrides allowed. Traditionally, you could only use .htaccess files when PHP was run as a module of Apache, but with Apache 2.2, this appears to no longer be the case. You can now use the .htaccess file in either module or cgi forms. As well, allowing the use of .htaccess files will cause a performance hit on the server, not a desirable outcome either - so check with your Host.


===Modifying the .htaccess file===
The .htaccess file is a distributed configuration file, that is, it can be used on a per-folder basis to configure each user's folder and sub-folders. You cannot alter the "AllowOverrides" directive in the Apache configuration file with a .htaccess file, only the Host can set that manually. Usually the Host will place a .htaccess file into your site Root if they do allow you to override the server settings. You can edit it the same as below, and the overrides you set will work. Alternatively, you may create your own .htaccess file in your text editor. It may also be called something else, like .config. If you have any file that starts with a ., you might want to open it in your text editor, just out of curiosity.  
{{stub}}
The following instructions will only work on an Apache web server, and also the Apache server must have Overrides allowed. Additionally php must be running as an apache module, not as a cgi program.


Create a file called .htaccess in Moodle's main directory (where 'index.php' is located, not the 'moodledata' directory) that contains the following information:
Create a file called .htaccess in Moodle's main directory (where 'index.php' is located, not the 'moodledata' directory) that contains the following information:
Line 97: Line 130:


20971520 is the integer value for 20Mb. You can use the following site to [http://www.onlineconversion.com/computer_base2.htm convert MegaBytes to Bytes].
20971520 is the integer value for 20Mb. You can use the following site to [http://www.onlineconversion.com/computer_base2.htm convert MegaBytes to Bytes].
For a more complete description of how to edit the .htacess file, look at this page, [http://httpd.apache.org/docs/current/howto/htaccess.html Apache Tutorial: .htaccess files]


===Modifying the IIS 7.0/7.5 configuration (Windows Server 2008, Windows Server 2008 R2)===
===Modifying the IIS 7.0/7.5 configuration (Windows Server 2008, Windows Server 2008 R2)===
Line 136: Line 171:
|[[Image:lightbulb.png]]
|[[Image:lightbulb.png]]
|Still not changed? Some hosts using cpanel have a php config program under services/software. Use the "Single php.ini" option and make sure you note the location of the php.ini file to modify. This changes the .htaccess file in the same area and thus the server limit for all programs using php.
|Still not changed? Some hosts using cpanel have a php config program under services/software. Use the "Single php.ini" option and make sure you note the location of the php.ini file to modify. This changes the .htaccess file in the same area and thus the server limit for all programs using php.
|}
{| class="nicetable"
|[[Image:lightbulb.png]]
|Still not changed? [http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size NGINX] system administrators should also add client_max_body_size XXXm; to the "http" section of their nginx main configuration file. ([https://rtcamp.com/tutorials/php/increase-file-upload-size-limit/#change-in-nginx-config see more info]) if you have SSL, that will require you to set the above for the SSL ''server'' and ''location'' too.
|}
|}


Line 141: Line 181:
*[[Administration_FAQ#How_do_the_limits_on_uploaded_files_work.3F|Administration FAQ Doc page]]
*[[Administration_FAQ#How_do_the_limits_on_uploaded_files_work.3F|Administration FAQ Doc page]]
*[[Site_policies#Maximum_uploaded_file_size|Site Policies Doc page]]
*[[Site_policies#Maximum_uploaded_file_size|Site Policies Doc page]]
*[[Installing_Moodle/Creating_custom_php.ini_files|Creating custom php.ini files Doc Page]]
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=39625 Detailed instructions to increase the maximum allowed size for uploaded files] forum discussion
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=39625 Detailed instructions to increase the maximum allowed size for uploaded files] forum discussion
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=97907 Instructions to increase maximum allowed size on hosted servers] forum discussion
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=97907 Instructions to increase maximum allowed size on hosted servers] forum discussion
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=124441 Help on changing the maximum upload size when installing Moodle via apt-get] forum discussion
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=124441 Help on changing the maximum upload size when installing Moodle via apt-get] forum discussion


[[Category:Administrator|File]][[Category:FAQ|File]]
[[es:Tamaño de archivo subido]]
 
 
[[Category:FAQ|File]]

Revision as of 14:24, 19 September 2019

Upload file size restrictions

Probably the most frequently asked question on moodle.org is "How do I increase the upload file size limit?" The changes that need be made are the same in all versions of Moodle, just in different OS' they need be made in different places. Upload file sizes are restricted in a number of ways and each one in this list restricts the following ones:

  1. Server level
  2. Moodle site level
  3. Course level
  4. Activity level

This is a contentious issue, mainly because you might think that it should be set inside the Moodle. Unfortunately, this is not so, these are environment issues that need to be set in the server and PHP folders, Moodle cannot work outside itself.

Physical access to Server

These instructions assume you have full physical and administrative access to your server. If you are using a hosted server then you will probably need to look into other ways to increase your file upload size.

There are positives and negatives to both methods below. If you modify the php.ini file then the changes will effect all php applications on your server. Since PHP5 you can only have one php.ini file on your server. The php.ini method will work with all web servers though. The .htaccess method will only effect the folder and all subfolders that it is placed in, but you must have certain settings enabled in Apache.

Restricting the File size - how it works

The Host may set a limit on the maximum file upload size in the Server environment, which you may override if the Host allows you to. PHP has a setting that it uses to limit the size of the file that it handles in upload. The Host has set that figure in the php.ini based on their particular perceptions and their clientele need. This size appears in Moodle in the Site administration > Security > Site security settings > Maximum uploaded file size drop-down combo box. You can change this at any time to suit your site need. In the Course Settings page, there is also a further restriction that can be made. At no time can the Course setting over-ride the Site setting, nor can the Site setting over-ride the php.ini setting, which cannot over-ride the Server setting. The only exception to this rule is that you can manipulate both the Server and the PHP settings, and how to do that is described below.

Modifying the php.ini file

These instructions show you how to change the file upload size by editing your php.ini file.

For the most part these instructions amount to the following. In the file /etc/php5/apache2/php.ini you need to change "post_max_size", "upload_max_filesize" and "max_execution_time" to values that suit your needs using whatever editor you are used to.

Below are some line by line instructions for various installations of Moodle.

Ubuntu Linux Instructions

These instructions assume that you have installed the standard Moodle package, PHP 5 and Apache 2 via apt-get and left it all as a default install. If you have compiled yourself I presume that you will know where your php.ini files are! NB As latest version of PHP is now 7.2+ you may need to find the file. If you run phpinfo() this should give you the correct location which will be something like: /etc/php/7.3/apache2/php.ini

You need to edit the following three settings in your php.ini file located at: /etc/php5/apache2/ Here are a set of instructions to follow line by line.

  • Type "sudo nano /etc/php5/apache2/php.ini"
  • Press Ctrl and W and type "post_max_size"
  • Change the value to the number of Mb you want your site to accept as uploads
  • Press Ctrl and W and type "upload_max_filesize"
  • Change the value to the number of Mb you want your site to accept as uploads
  • Press Ctrl and W and type "max_execution_time"
  • Change the value to 600
  • Press Ctrl and O
  • Press Ctrl and X
  • Type sudo apachectl restart


NGINX system administrators should also add "client_max_body_size XXXm;" to the "http" section of their nginx main configuration file. (see more info) if you have SSL, that will require you to set the above for the SSL server and location too.

Your new file size limit should now appear in Administration > Security > Site Policies > Maximum uploaded file size

XAMPP on Mac Instructions

These are instructions for how to do this for Moodle on a Mac using the XAMPP sample download package available. (This is not for a OS X production server.)

  • Close down Apache and MySQL if they are running via the XAMPP Control app and close the XAMPP Control app
  • Open Finder and go to Applications
  • Navigate down and open the folder XAMPP / xamppfiles / etc
  • Open the file php.ini with TextEdit (or another plain text editor)
  • Search for the post_max_size setting and up this from 128M (the default) to more; 500M is the maximum
  • Do the same for upload_max_filesize (make the numbers the same)
  • Search for the max_execution_time setting and up this to 300 (or more if you get timeouts on uploads)
  • Save the php.ini file
  • restart Apache and MySQL as usual


Note: You may get a "permission denied" error when saving the php.ini file unless you are logged in with admin access to your Mac. To work around this, you can set the /etc directory in which the php.ini file is located to be writable temporarily. For how to do that, see here or here.

Windows XP and Server 2003 Instructions

These instructions presume that you have downloaded the latest PHP 5.3.x Windows zip package and extracted it to C:\PHP. If you have installed PHP to another location then change all references to "C:\PHP" to the location you installed PHP too.

lightbulb.png Download and install any text editor that can save the file in a UTF-8 format, Crimson Editor is one such, NotePad++ is another, use that instead of either Wordpad or Notepad! The issue is that WordPad or Notepad will include hidden characters that may not be compatible with the requirements of PHP.
  • Open C:\PHP
  • Right Click the php.ini file in this folder and choose "Open with..." selecting your editor of choice.
  • Press Ctrl + F and type "post_max_size" (click Find...", where needed)
  • Change the value to the number of Mb you want your site to accept as uploads
  • Press Ctrl + F and type "upload_max_filesize" (click Find...", where needed)
  • Change the value to the number of Mb you want your site to accept as uploads
  • Press Ctrl + F and type "max_execution_time" (click Find...", where needed)
  • Change the value to 600
  • Press Ctrl and S or the save button.
  • Exit your editor.
  • Restart your webserver to reload PHP with the edited changes.
    • For IIS
    • Open the Start Menu on your server and select "Run"
    • Type "iisreset /RESTART"
    • For Apache 2 and Windows XP
    • Go to Start > All Programs > Apache > Restart
    • For Apache 2 and Windows Server
    • The following command will work as long as you have installed Apache 2 as a service on your Windows Server
    • Open your Start Menu on your server and select "Run"
    • Type "httpd -k restart"

Your new file size limit should now appear in Administration > Security > Site Policies > Maximum uploaded file size

NOTE: These instructions also cover the Xampp Windows installer. Just replace C:\PHP with C:\Moodle\server\php and to restart your Moodle with a normal stop-start.

Modifying the apache config file

Ubuntu Linux Instructions

You may also need to edit the config.php file in the moodle directory:

  • Type "gksudo nautilus" to get root permissions
  • Navigate to /etc/moodle
  • Open apache.conf
  • Go to the "<IfModule mod_php5.c>" section
  • Change "php_value upload_max_filesize = 2M" to a higher value
  • Change "php_value post_max_size = 2M" to a higher value
  • Go to the "<IfModule mod_php4.c>" section
  • Change "php_value upload_max_filesize = 2M" to a higher value
  • Change "php_value post_max_size = 2M" to a higher value
  • Save file
  • Type sudo /etc/init.d/apache2 restart

Modifying the .htaccess file

The following instructions will only work on an Apache web server, and also the Apache server must have Overrides allowed. Traditionally, you could only use .htaccess files when PHP was run as a module of Apache, but with Apache 2.2, this appears to no longer be the case. You can now use the .htaccess file in either module or cgi forms. As well, allowing the use of .htaccess files will cause a performance hit on the server, not a desirable outcome either - so check with your Host.

The .htaccess file is a distributed configuration file, that is, it can be used on a per-folder basis to configure each user's folder and sub-folders. You cannot alter the "AllowOverrides" directive in the Apache configuration file with a .htaccess file, only the Host can set that manually. Usually the Host will place a .htaccess file into your site Root if they do allow you to override the server settings. You can edit it the same as below, and the overrides you set will work. Alternatively, you may create your own .htaccess file in your text editor. It may also be called something else, like .config. If you have any file that starts with a ., you might want to open it in your text editor, just out of curiosity.

Create a file called .htaccess in Moodle's main directory (where 'index.php' is located, not the 'moodledata' directory) that contains the following information:

php_value upload_max_filesize 20971520
php_value post_max_size 20971520
php_value max_execution_time 600

20971520 is the integer value for 20Mb. You can use the following site to convert MegaBytes to Bytes.

For a more complete description of how to edit the .htacess file, look at this page, Apache Tutorial: .htaccess files

Modifying the IIS 7.0/7.5 configuration (Windows Server 2008, Windows Server 2008 R2)

First increase activity and request time outs (allows large files to succeed on slow connections)

FastCGI Settings > Edit (Right-click on PHP application)
Set Process Model > Activity Timeout to '3600' (one hour)
Set Process Model > Request Timeout to '3600' (one hour)

Next set 'Maximum allowed content length'

Request Filtering > Edit Feature Settings:
Set 'Maximum allowed content length' to your desired file size (in bytes) e.g. '536870912' for 512MB (default is approximately 28.6MB)

Hosted Server

Things can be a little different with a hosted server for uploaded and downloaded file size. You are probably going to to be told to create or change a .htaccess file, or to modify a php.ini file.

lightbulb.png It might be a good idea to talk to with your service provider before you attempt anything. They probably have instructions on "how to" and may have their own limits for uploaded file size. Some hosts measure the file size in gigabytes and others in megabytes. If you are unhappy with their limits, then check your contract and consider changing your provider to one that has a limit and price that you like.

.htaccess with hosted server

The one purpose of an .htaccess file is to override the the current limitations of both the server and the php.ini file. Your hosted server should inform you where that file needs be placed in your Moodle, but generally in the root is sufficient. They may already have a standard file you can use, if so, use it - but perhaps not.

To the .htaccess file add the lines:

 php_value upload_max_filesize 128M
 php_value post_max_size 128M
 

This will limit uploads to 128MB, but you can make it any size you agree with your provider. The wording may vary slightly, according to the demands of the server.

php.ini with hosted server

Some servers will not allow you to change the moodle root .htaccess file and tell you to use a php.ini file for php directives. Here you can use the instruction located in the section above called Modifying the php.ini file.

Find the php.ini file in your moodle subfolder on your hosted server. You might want to copy the file as a backup just in case. Edit php.ini, find "upload_max_filesize" and post_max_size in the code. After the = change the number. Here the max filesize is 20 megabytes.

upload_max_filesize = 20M
post_max_size = 20M
lightbulb.png Still not changed? Some hosts using cpanel have a php config program under services/software. Use the "Single php.ini" option and make sure you note the location of the php.ini file to modify. This changes the .htaccess file in the same area and thus the server limit for all programs using php.
lightbulb.png Still not changed? NGINX system administrators should also add client_max_body_size XXXm; to the "http" section of their nginx main configuration file. (see more info) if you have SSL, that will require you to set the above for the SSL server and location too.

See Also