Cannot increase upload size past 2MB

Cannot increase upload size past 2MB

by JP Burke -
Number of replies: 40
I have been trying for several hours now to increase the maximum upload size for a class past 2MB. After reading just about every forum post related to this topic I had quadruple checked my php.ini, my httpd.conf, and my Moodle systemwide setting. I have restarted Apache and even rebooted the entire system for good measure. Nothing I can do will raise the limit past 2MB.

Can someone please help me out?
Average of ratings: -
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Matt Gibson -
Sometimes there is more than 1 copy of php.ini. Ensure you have the right one by deliberately adding a load of rubbish to it and seeing if that prevents apache from starting smile

Which settings were you altering in php.ini? There are 2 as I remember.
Average of ratings: Useful (1)
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Skylar Saveland -
If you are some unix you should have:

$ sudo updatedb # or something else for other distro
$ locate php.ini # hopefully you have locate

alternately you might have find:

from the root dir:
$ find . -name php.ini

This can take some time to run.

Sorry if this is too basic or too linux to be helpful but I'm new to Moodle and php smile.
Average of ratings: Useful (1)
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Alan Trick -

The first thing I would to is locate the source of the problem. Create a PHP file with the following code:

<?php
header('Content-Type: text/plain');
$settings = array('upload_max_filesize','post_max_size');
foreach ($settings as $setting) {
 print "$setting: ".ini_get($setting)."\n"
}

The post_max_size should be larger than upload_max_filesize (otherwise you get funny problems). The reason is that if a file is too large and the limits are the same, it may cause the other data in the POST request to go missing.

The settings file_uploads, max_input_time, and memory_limit may affect uploads as well, check these settings if you continue to have problems.

If these numbers are okay, then it's an issue with Moodle, otherwise it's an issue with your PHP settings.

Average of ratings: Useful (1)
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
I hesitate to suggest anything when someone starts out by saying they have read everything, so at the risk of suggesting you look at something you already worked through, I would suggest that you first identify whether you are running php 4 or 5 as their is a huge difference when it comes to sourcing php.ini and you make no mention of this. You might review the material posted on how php.ini is sourced as that will help you to determine whether your php.ini is being sourced at all and how to determine where the sourced php.ini is located. You have undoubtedly already increased the limit as Moodle admin in site policies, but you made no metnion of that either, so one needs to inquire ;=} Likewise, absent a presentation by you of your php.ini one has to wonder if you increased BOTH settings in your php.ini.

You should read the docs first (you don't mention reading the docs....) Are you running php as cgi, and if so, why did you restart apache? Might you want to zip and upload your php.ini?
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by JP Burke -
I am using PHP5.

I have two php.ini files: /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini. I changed both files just to be on the safe side.

In both files I changed these settings:
max_execution_time = 300
max_input_time = 600
memory_limit = 1024M
upload_max_size = 1024M
post_max_size = 1024M

When I run the test script suggested above it indicates that both upload_max_size and post_max_size are 1024M. (In case you are wondering, we will only be using moodle over a local network so file size is not a problem)

In moodle, under Security > Site Policies I have set Maximum uploaded file size to 1073741824.

However, despite all of this when I go to edit a specific course the only options I have under Maximum file size are: 2MB, 1MB, 500k, 100k, 50k, 10k.

I have read everything I could find on the Moodle site, forums and docs included, on how to set the maximum upload size and it seems like I'm doing everything right. What have I missed?

In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Alan Trick -
You should be able to just use the Site-wide limit (i.e. don't limit on a per-course basis).
In reply to Alan Trick

Re: Cannot increase upload size past 2MB

by JP Burke -
Well, first of all, if I wanted to limit on a per class basis I should be able to (since it is a feature)

Secondly, I'm not trying to. I'm trying to raise the limit on the classes so high that the upload limit is never an issue. I have set my site-wide limit to a whole gigabyte but the highest option I have available on each class is 2 megs. Hence the problem.
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
Just for grins, let's assume you are running php as cgi ....
set your /etc/php5/cli/php.ini to these settings (if you are running mod_php you will want to change both especially if you are involking cron via CLI

; Maximum size of POST data that PHP will accept.
post_max_size = 28M
; Maximum allowed size for uploaded files.
upload_max_filesize = 28M

and remove the php size settings from any htaccess files.....

and now go check your Moodle GUI and see what shows up.....
Read the php docs on the diff between post and upload max file sizes and play with these until you feel comfortable.

If you really want to push the envelope, after checking your apache limits try

; Maximum size of POST data that PHP will accept.
post_max_size = 1G
; Maximum allowed size for uploaded files.
upload_max_filesize = 1G

But consider the comments below..
  • you probably do not want to use Moodle scripting to upload 1 gig files; use ftp (I suppose that at some point where expected assignment files become that large, more effective tools for large file transfer may be implemented).
  • there are other apache (e.g. limitrequestbody and large file support) and OS limitations (such as whether this is a 1`6bit, 32 bit or 64 bit OS) and as you push limits things will break , especially if you set applications to use resources that are not otherwise made available.
In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
When you ask if I'm running php as cgi wht do you mean? I was under the impression that php always ran as a cgi.

In /etc/php5/cli/php.ini I have post_max_size and upload_max_filesize both set to 1G. When I run a test script to output what the values are set to it correctly lists them as 1G.

The Moodle GUI STILL will only list 2MB as the highest available option under "Maximum upload size" on the course settings.

In my flailing around trying to get this to work I have done everything I can think of, even if it probably wouldn't make a difference including rebooting the machine, restarting Apache, adding .htaccess files that specific the LimitRequestBody again (since I have already set that in httpd.conf to 2147483647). I have also logged in and out of Moodle, refreshed the page, cleared the cache and refreshed the page.

What is the deal here??
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
You can run php as cgi or via mod-php. You may want to double check your apache config and confirm how you are running php.... if you are running via cgi, then each time you invoke php it is a new instance and the php.ini gets read, i.e. no need to restart apache.

Please follow the steps I suggested and then advise of the results....
In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
Ah. I don't believe I'm running mod_php but would it make any difference other than my potentially useless restarting of the server?
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
yes, your php setup has different ini file for cli
Did you already do what I suggested and if so can up zip and upload a screen capture of your moodle php info page and you php.ini files? In the interim I would reduce file size in both php.ink files to 1M and if that is not reflected in your moodle install I am guessing that there is another php.ini file somewhere....

Is this installation on your own server or on a web host?
In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
This is on my own server.

I changed both php.ini files and when I had php output what it was storing for those values the values were correct.

Attached is my php.ini file (both are identical). Right now I have the sizes set in bytes but I have also tried 1G and 1024M.
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
Please go back, read my suggestions and advise on the results
check all htaccess and delete file size limits
reset apache limit
set php.ini sizes to "28M" not in bytes
capture phpinfo page and upload it and your php.ini as a zip
and then restart apache (and double check whether you are running mod_php)
If still no joy set both your php.ini files to 1M and try again and see if the change down is reflected in the drop down.
In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
What's the point of getting it to work with 28M if it won't work with 1024M, which is what I actually need?

Thanks for all your help. I'll take another crack at this on Monday and try 28M.
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Frank Ralf -
I haven't tried any of the tips myself so far, but I got a bit suspicious of the reference to exactly "2MB". So I did a search in all of the Moodle code with the result as seen in the screenshot. Looks like there are some internal 2 MB limits within the Moodle code itself.

hth
Frank
Attachment Moodle_references_to_2MB.png
In reply to Frank Ralf

Re: Cannot increase upload size past 2MB

by Alan Trick -
The matches in filelib.php are misleading. That has to do with how much can be read at a time. When ever you make a request to read a file on a computer, you have to specify how much you want to read. Typically if you want to read the whole file, you'll just loop until you reach the end of the file.
In reply to Frank Ralf

Re: Cannot increase upload size past 2MB

by Marc Grober -
That's chunk size, not max file size, but I suppose the chunk fix could also have broken something else and that this could be what is in issue.... Would need to know if code change predated jp's build and would need to sniff out php logs - did you run down the tracker entry on the change?
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
The point is to reduce the number of potential variables you have introduced into the problem. If your phpinfo page reflects the same values you are setting and those values are such that I know they should not run afoul of anything else then it suggests that max values are being ceilinged elsewhere, and if you then can't set to 1M then it suggests you have no control over php.ini

That is the thrust of the suggestion as well that you sabotage your php.ini file to determine if it's even being read-and doing a find as root will assist in addressing that-which is one reason I am assuming per your prior post that you read the links to how php.ini is sourced.

Likewise confirming you are not running mod_php will help to determine what apache is doing, and cleaning out changes to apache don't files and any htaccess files will also help reduce possible issues.
In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
So, I decided to skip straight to the test where I set the PHP upload limit lower than the 2MB cap I currently have on my course settings. My phpinfo page reflects this change but my course settings do not (I made sure to restart Apache). With the upload limit set to 64K my choices are unchanged in the "edit course settings" page. I still have 2MB listed as my top choice, even though it shouldn't be available.

Is there no place I can configure these preset upload limits? Or does Moodle have to figure it out on its own based on the server environment?
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
There is an array from which the dropdown is created, but this is behavior that is typical of what we would see with php4.... the php.ini sources by phpinfo is read, but file upload is not impacted because there is no ini file in the necessary sub directories..... I know you don't want to hear this but this is very interesting. Just to address this quickly do a symlink from your cli php.ini to the directory in which the php to upload for the module you are using lives (let me know if you need on this) and then see if the response changes. If it does it means that something in your install has changed what was the default php5 behavior and the docs need to be updated to reflect that.

I am on the road and can't see the file you uploaded, but should be able to do that today.... In the meantime have a look at http://www.askapache.com/php/custom-phpini-tips-and-tricks.html
In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
I tried symlinking the php.ini file to the folder where the php file lives (/usr/share/moodle/courses/edit.php) but still no dice.

Is it possible that this is a bug with Moodle?
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
ln -s /etc/php5/cli/php.ini /absolutepathtoyourmoodle/admin
And then the same for /course and /file

Not sure what your post re edit.php meant......
In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
Sorry, what I meant was that the "edit course settings" page is /usr/share/moodle/course/edit.php so just to make sure it had access to the php.ini file I put the symlink in the /usr/share/moodle/course folder.. with no results.

On your suggestion I just adding symlinks to /course and /files and will have no results.


I don't understand what the problem can be at this point. PHP's settings are clearly correct. Apache's settings are clearly correct. Moodle's global settings are clearly correct. It is just this one dropdown that is preventing me from doing what I need to do.
In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
Despite my php.ini file being symlinked to all of these directories I am still having trouble.

At this point I am trying to limit my filesize just as a test to see if I can control the value at all. My maximum filesize, as far as php is concerned, should be 64k. However, I still have 2MB listed as an option.

I tried lowering Moodle's system setting and that successfully lowered the maximum upload size. I then incrementally increased the size and found that it caps at 2MB. Is there some other Moodle setting that prevents the system from going past 2MB?
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
Sorry I have not been available..... teeth were not cooperating ;)

This represents a step forward as to date you have indicated that mOOdle has not responded at all to changing the php.ini entries.

Max size should only be controlled by Apache conf or htaccess files (either through limitbody or php_values being set), the max your OS can handled, and max set in php.ini

Did you determine whether you were running mod_php and are you setting both of the php.ini files in /etc?

Did you look at the doc I sent you regarding setting the php env so php knows where to look for a single php.ini?
In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
No worries, teeth problem are the worst.

I am not running mod_php.

Actually I'm not sure that Moodle has responded to changing the php.ini entries. I'm saying that I changed the site policy max filesize in Moodle's configuration (under Security) and that's how I was able to lower the maximum filesize. What I found striking was that I could dial the Moodle settings down as much as I wanted but the second I passed 2MB it stopped responding.

To make sure Apache is not a part of the equation I set the limit to Apache's maximum of 2 gigabytes in my httpd.conf file. I have both php.ini files set to the same values (just to be safe) and I have one of them symlinked in several directories in my Moodle folder structure.

PHP tests still respond to changes made in my php.ini files. It seems that the only piece that's not responding is that one dropdown in the course settings. Is it possible to manually add new values that would override the current 2MB cap?
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
Try something for me.... change limitrequestbody to 0. Set your php.ini lines to 20M in both your php.ini files and copy php,ini to your cgi-bin and restart apache and see if that does anything.... As long as moodle believes there is a 2MG max because that us what it's getting from php we are not going to fool it
In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
* Set LimitRequestBody to 0 in my main httpd.conf.
* Killed any .htaccess files just to make sure they're not responsible
* Changed both /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini (the only two php.inis on the system other than the symlinks) to be 20M under both upload_max_filesize and post_max_size
* Restarted Apache

Still no joy sad
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
did you put a copy of php.ini in your cgi-bin?
In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
Ah, forgot to mention that. Yep, I also put a symlinked php.ini in my cgi-bin.
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
Well, I am dumbfounded......... did you try setting the location of the php.ini file via the environment yet? If you are running php as cgi then the php.ini should be in the directory of the php executable.... which in many cases is the cgi-bin..... how have you set up running php as cgi (see resources below)?

If you don't want to set PHPRC in your server's environment or set phpinidir in your apache conf file, let's try deleting the symlinks and copy the ini file to the admin, course, and files directories as well as to the cgi-bin directory, or where ever php is being executed from as a CGI... if this has been compiled as CGI then your php file is what is executed so with force redirect you would likely had a file named php in your cgi-bin, which would be the executable for cgi, and therefore it would be from cgi-bin that your ini file would be read. http://us2.php.net/manual/en/security.cgi-bin.force-redirect.php

It still looks to me like this is a directory by directory issue resulting from the fact that php is sourcing the ini file based on the working directory when the call is made, which suggests that in setting limits the 2M default is being used in some instances because of that context.. As I mentioned, if you set php to use the correct ini file then this should no longer be an issue (though please make sure that none of your apache conf files (there are a few....) or htaccess files are interfering with php directives.....

Here's the links I provided before.....
http://www.askapache.com/2007/php/custom-phpini-tips-and-tricks.html
http://us2.php.net/configuration

If all else fails, let's turn up php debugging and let's see if the log files will give us some idea of what Moodle is doing....



In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
SUCCESS!!

Alright, here's the deal. In my /etc/apache2/conf.d folder was a file called "moodle" that had some PHP settings including (wait for it) a 2MB file upload cap.

Everything's working now! Thanks for the help everyone, especially Marc!
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
Great, JP! However, we should add info about this to the docs, soooo: I assume that the file you found is an apache conf file (not a php style file); I'd like to document answers to the following questions and would appreciate whatever help you can offer to that end.

How did the file get created?
Did you just delete the file or did you change settings?
What happens if you delete it?
What's in the file?
I assumed you built this install, but when I went back through the posts you only said it was your server; did you use a distro from moodle like lamp (ie is this conf file an undocumented feature?)
is this file actually referenced by one of the apache conf files or is it sourced only because it's in conf.d?
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
Great, JP! However, we should add info about this to the docs, soooo: I assume that the file you found is an apache conf file (not a php style file); I'd like to document answers to the following questions and would appreciate whatever help you can offer to that end.

How did the file get created?
Did you just delete the file or did you change settings?
What happens if you delete it?
What's in the file?
I as
In reply to JP Burke

Editing apache.conf to increase max upload

by Marc Grober -
Very strange..... seems like somehow two drafts of my post were published.... LOL

In any event, if you look here:
http://docs.moodle.org/en/Step-by-step_Install_Guide_for_Ubuntu_using_apt-get
you will find a discussion of the moodle file you discovered,

This moodle install will only work from the localhost. To make it accessible from other hosts you must edit the file /etc/apache2/conf.d/moodle. Type

sudo nano /etc/apache2/conf.d/moodle

(This is actually a soft link from /etc/moodle/apache.conf). This fires up the 'nano' text editor which is command line text editor and the sudo gives you the write access you need.

There is also extensive discussion about linking /etc/moodle/apache.conf with /etc/pache2/conf.d/moodle

And here is a discussion on the packaging specifics peculiar to some forms of linux:
http://www.control-escape.com/web/configuring-apache2-debian.html

As you can see, apache will read as conf files the contents of conf.d, so it is "easier" to set moodle apache conf directives in /etc/moodle/apache.conf, which through linking to the apache conf.d directory, are read when you force apache to reread conf files via a restart....

Of course, none of this is apparently documented in the docs vis-a-vis changing file limits.... LOL.... and I will try to get to that, but if you would like to experiment so that the docs could address some examples (deleting the file, commenting out the directives, use of the file instead of a custom php.ini, etc) that would be great.....
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Marc Grober -
Btw, my initial guess would be that php is looking in the working directory because it can't find php.ini in a location higher in the search order, which leaves me wondering how phpinfo found it, but i can't do much more at the moment.... But if this is the culprit, than doing the symlink or setting the env will fix it...

See http://moodle.org/mod/forum/discuss.php?d=94601&parent=417707 for directories, but setting env correctly much preferred
In reply to Marc Grober

Re: Cannot increase upload size past 2MB

by JP Burke -
Is there anything else I have to change to just get the menu under "Edit course settings" to reflect the changes I've made to the server? At this point I've done everything I can think of to the server with no luck. Is it possible to manually edit the menu controlling maximum upload size?
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by Jim Brown -
I have the exact same problem. Max upload size in the drop-down list is 2MB the highest setting in the box under the Course settings. I am running Moodle 1.9 on Ubuntu 9 w/mysql
In reply to JP Burke

Re: Cannot increase upload size past 2MB

by E. L. Cooper -

two places to check

Administration   Courses   Course default settings and

Administration Security Site policies