Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory limit quite low #182

Closed
nalt opened this issue Nov 14, 2017 · 30 comments
Closed

Memory limit quite low #182

nalt opened this issue Nov 14, 2017 · 30 comments

Comments

@nalt
Copy link

nalt commented Nov 14, 2017

The php memory_limit is not set and thus defaults to 128M. This results in a crash, when I try to generate thumbnails of photos taken with a standard digital camera usingocc preview:generate-all.

A larger memory limit is required for this standard task. It should be ok to increase it on installations that target only small groups of users.

Possible solutions:

  • Explicitly set (a larger) memory_limit in Dockerfile
  • Allow to set the memory limit with an ENV var
  • Add a php-override.ini and document how to use it. Advantage: This would allow for all kinds of custom tweaks to php.ini
@Zogg
Copy link

Zogg commented Mar 11, 2018

Bump. Having the same issue.

@Svarto
Copy link

Svarto commented May 16, 2018

Hi, I have similar errors being thrown in my nextcloud install, any updates / working solutions to this?

@pierreozoux
Copy link
Member

What should be the limit in your opinion?

@jkaberg
Copy link

jkaberg commented May 16, 2018

@pierreozoux make it optional with a default (docker ENV) option?

@pierreozoux
Copy link
Member

Does anybody want to PR this?

@monreal
Copy link

monreal commented Aug 31, 2018

What would be the best workaround until this is implemented? I would like to set it to 512MB

@FriedCircuits
Copy link

@monreal I used Ansible to update the .htaccess file inside the docker from 512M to 2G after the docker is deployed. Looks like the default is now 512M.

@monreal
Copy link

monreal commented Sep 1, 2018

@FriedCircuits for me it is still 128mb with 14rc. Do I have to change it manually in Nextcloud's .htaccess because it was not updated manually? Also I wonder why there is no php.ini at all

@monreal
Copy link

monreal commented Sep 1, 2018

So, I actually got memory_limit=512M in my .user.ini
I guess occ does not get its setting from there? I noticed when I had to manually create some DB indices after the NC14 upgrade. The occ command worked but printed a warning about the setting being lower than the recommended 512mb. PHP default seems to be 128mb so without a php.ini I guess it is using that...

@ptrunk
Copy link

ptrunk commented Sep 7, 2018

I am using the fpm-alpine image so i am not sure if it works for all images.

Because both php-cli and php-fpm support variable substitions i would suggest to use a custom /usr/local/etc/php/conf.d/nextcloud.ini with variables which should be changeable by the user. This file could be installed by the Dockerfile.

For Example

nextcloud.ini

memory_limit=${PHP_MEMORY_LIMIT}

Dockerfile

[...]
ENV PHP_MEMORY_LIMIT=512M
COPY nextcloud.ini /usr/local/etc/php/conf.d/nextcloud.ini
[...]

Now the user can run this image with -e PHP_MEMORY_LIMIT=1G and increase the limit.

@FriedCircuits
Copy link

@ptrunk That would be great and would work better with docker swarm since the container can be rebuilt at anytime. I hope someone at nextcloud can resolve this as it coming up on a year.

@ptrunk
Copy link

ptrunk commented Sep 14, 2018

The php cli memory_limit problem is apparently fixed now by #460 but i am not sure a hardcoded value of 512M is the way to go because it still could be too low in some cases.

If someone wants to try i have created a custom docker image based on nextcloud:14.0.0-fpm-alpine with an environment variable PHP_MEMORY_LIMIT [1].

docker pull registry.gitlab.com/p7k/docker-nextcloud/nextcloud-fpm:14.0.0-1

I would prefer to have this kind of configuration also for other variables instead of using a .user.ini file but this is just my personal opinion.

[1] https://gitlab.com/p7k/docker-nextcloud/tree/master/fpm

@FriedCircuits
Copy link

@ptrunk Cool, I may it give it a try. I never could get the FPM to work with nginx/docker-proxy but now I am migrating to traefik so maybe it will work.

In my case 512M isn't enough. I need at least 1G. I can't remember why I was hitting the limit. I have external mounts and elasticsearch setup.

@gladiac
Copy link

gladiac commented Sep 24, 2018

Hello everybody,
so, the nextcloud docker-image comes by default with a .user.ini inside the document-root of nextcloud which already has 512M configured. However, just running

docker exec --user 33 -ti nextcloud occ preview:generate-all

is not enough to make use of it - it instead still falls back to the 128M that PHP considers to be default. To actually use .user.ini I came up with the following solution:

docker exec --user 33 -ti nextcloud php -c .user.ini -f occ preview:generate-all

This runs occ inside the container (in my case "nextcloud") as user 33 (which is www-data) but does it in a way so that PHP loads the configuration from .user.ini before. This way, you can configure whatever PHP option you want and it even is persistent if you made /var/www/html a docker-volume.
Hope that helps.
cheers, chris

@FriedCircuits
Copy link

FriedCircuits commented Sep 25, 2018

I ended up making a new Dockerfile based on the official one. Way better than having to modify the image afterwards everytime time there is an update. I can just run my Ansible playbook to update the Dockerfile and rebuild image.

https://hub.docker.com/r/mobilewill/nextcloud-full-mem2g/

@Mr-Oca
Copy link

Mr-Oca commented Sep 27, 2018

I'm using the "linuxserver/nextcloud" image and I have the same issue. I tried to run
docker exec --user 33 -ti nextcloud php -c .user.ini -f occ preview:generate-all
but I couldn't make it to work (yes, I did adapte it to my setup) : TTY problem then no output log empty.
I there a simple way to fix this memory problem ?

@FriedCircuits
Copy link

@kjlhgfds Before I made the Docker image I was adding the memory limit to the nextcloud .htaccess file. That was the only way that worked for me. You have to make the change every time you redeploy the image so I did it with Ansible.

@Mr-Oca
Copy link

Mr-Oca commented Sep 27, 2018

I already have
php_value memory_limit 512M
under both
<IfModule mod_php5.c>
and
<IfModule mod_php7.c>

Did you add anything else ?

@FriedCircuits
Copy link

@kjlhgfds I looked at my Ansible tasks to see how I did it. I did a regex and updated the current value already in the .htaccess in the /html directory and replaced 512M with 2G.

@Mr-Oca
Copy link

Mr-Oca commented Sep 29, 2018

@FriedCircuits I don't have a /html directory.
I have a .htaccess in the /www directory, in wich I changed both php_value memory_limit from 512M to 2G.
Still have the same problem : /

Here is my .htaccess :

<IfModule mod_headers.c>
  <IfModule mod_setenvif.c>
    <IfModule mod_fcgid.c>
       SetEnvIfNoCase ^Authorization$ "(.+)" XAUTHORIZATION=$1
       RequestHeader set XAuthorization %{XAUTHORIZATION}e env=XAUTHORIZATION
    </IfModule>
    <IfModule mod_proxy_fcgi.c>
       SetEnvIfNoCase Authorization "(.+)" HTTP_AUTHORIZATION=$1
    </IfModule>
  </IfModule>

  <IfModule mod_env.c>
    # Add security and privacy related headers
    Header set X-Content-Type-Options "nosniff"
    Header set X-XSS-Protection "1; mode=block"
    Header set X-Robots-Tag "none"
    Header set X-Download-Options "noopen"
    Header set X-Permitted-Cross-Domain-Policies "none"
    SetEnv modHeadersAvailable true
  </IfModule>

  # Add cache control for static resources
  <FilesMatch "\.(css|js|svg|gif)$">
    Header set Cache-Control "max-age=15778463"
  </FilesMatch>

  # Let browsers cache WOFF files for a week
  <FilesMatch "\.woff$">
    Header set Cache-Control "max-age=604800"
  </FilesMatch>
</IfModule>
<IfModule mod_php5.c>
  php_value upload_max_filesize 511M
  php_value post_max_size 511M
  php_value memory_limit 2G
  php_value mbstring.func_overload 0
  php_value always_populate_raw_post_data -1
  php_value default_charset 'UTF-8'
  php_value output_buffering 0
  <IfModule mod_env.c>
    SetEnv htaccessWorking true
  </IfModule>
</IfModule>
<IfModule mod_php7.c>
  php_value upload_max_filesize 511M
  php_value post_max_size 511M
  php_value memory_limit 2G
  php_value mbstring.func_overload 0
  php_value default_charset 'UTF-8'
  php_value output_buffering 0
  <IfModule mod_env.c>
    SetEnv htaccessWorking true
  </IfModule>
</IfModule>
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_USER_AGENT}  DavClnt
  RewriteRule ^$         /remote.php/webdav/          [L,R=302]
  RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
  RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
  RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
  RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
  RewriteRule ^remote/(.*) remote.php [QSA,L]
  RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
  RewriteCond %{REQUEST_URI} !^/\.well-known/(acme-challenge|pki-validation)/.*
  RewriteRule ^(?:\.|autotest|occ|issue|indie|db_|console).* - [R=404,L]
</IfModule>
<IfModule mod_mime.c>
  AddType image/svg+xml svg svgz
  AddEncoding gzip svgz
</IfModule>
<IfModule mod_dir.c>
  DirectoryIndex index.php index.html
</IfModule>
AddDefaultCharset utf-8
Options -Indexes
<IfModule pagespeed_module>
  ModPagespeed Off
</IfModule>
#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####

ErrorDocument 403 //
ErrorDocument 404 //

@FriedCircuits
Copy link

@kjlhgfds I found this in my custom dockerfile that might help

echo 'memory_limit=2G' > /usr/local/etc/php/conf.d/memory-limit.ini

@lhurt
Copy link

lhurt commented Oct 17, 2018

Hi,
there's a way without touching the image at all. In my docker-compose.yml there are two lines in the volumes: section allowing container specific configuration.

      - ./etc/php-fpm.d/www.overloaded.conf:/usr/local/etc/php-fpm.d/www.overloaded.conf
      - ./etc/php/conf.d/nextcloud.ini:/usr/local/etc/php/conf.d/nextcloud.ini

The file www.overloaded.conf is for overloading some values in the fpm module as I want to set my own server values. The default values in the image are set in a file called /usr/local/etc/php-fpm.d/www.conf and as the files in php-fpm.d/ are evaluated in alphabetic order I chose www.overcload.conf to make sure its read afterer www.conf.

[www]
pm = dynamic
pm.max_children=100
pm.start_servers=10
pm.min_spare_servers = 4
pm.max_spare_servers = 10
;pm.process_idle_timeout = 10s;
;pm.max_requests = 1000

nextcloud.initakes care of the memory settings and some other php settings.

[PHP]
memory_limit = 8G
upload_max_filesize= 10G
post_max_size = 11G
max_execution_time = 3600
max_input_time = 3600

Because both files are located in a local directory it's very easy to change them. As soon as the container is restarted they are effective. No image generation required.

Hope that helps.

@kosli
Copy link

kosli commented Nov 5, 2018

@lhurt the trick with the memory_limit setting in the nextcloud.ini sets for me the memory_limit on the "global" php level, whereas the "local" level is overwritten by the .htaccess file which has:

<IfModule mod_php7.c>
  php_value upload_max_filesize 511M
  php_value post_max_size 511M
  php_value memory_limit 512M
  php_value mbstring.func_overload 0
  php_value default_charset 'UTF-8'
  php_value output_buffering 0
  <IfModule mod_env.c>
    SetEnv htaccessWorking true
  </IfModule>
</IfModule>

If I comment the memory limit in the .htaccess, then it works as expected, but this is still a manual workaround. How have you solved that? I am useing the nextcloud:14-apache image

@ludwighurt
Copy link

@lhurt the trick with the memory_limit setting in the nextcloud.ini sets for me the memory_limit on the "global" php level, whereas the "local" level is overwritten by the .htaccess file which has:

<IfModule mod_php7.c>
  php_value upload_max_filesize 511M
  php_value post_max_size 511M
  php_value memory_limit 512M
  php_value mbstring.func_overload 0
  php_value default_charset 'UTF-8'
  php_value output_buffering 0
  <IfModule mod_env.c>
    SetEnv htaccessWorking true
  </IfModule>
</IfModule>

If I comment the memory limit in the .htaccess, then it works as expected, but this is still a manual workaround. How have you solved that? I am useing the nextcloud:14-apache image

No. I'm using the nginx php-fpm image combination.

Sorry.

You could try to supersede the .htaccess file in the docker-compose.yml by adding - <path to your local .htaccess file>:/var/www/html/.htaccess. The downside is that you have to copy and edit the .htaccess file from the distribution every time. Otherwise consider a change the webserver.

Hope that helps.

@J0WI
Copy link
Contributor

J0WI commented Nov 4, 2019

A solution has been posted in #182 (comment), so I'll close this.

@J0WI J0WI closed this as completed Nov 4, 2019
@MichaelUray
Copy link

My allowed memory size is 2 GB, but I still get this error for allocating just 16 MB.

PHP Fatal error: Allowed memory size of 2,147,483,648 bytes exhausted (tried to allocate 16,059,048 bytes) in /var/www/html/lib/private/legacy/OC_Image.php on line 649

Why does this happen?

@FarisZR
Copy link
Contributor

FarisZR commented Feb 18, 2021

you don't need to override the entire nextcloud.ini anymore, there is a separate file for memory limit, its called memory-limit.ini

make sure to create a file called memory-limit.ini to mount into, just put memory_limit=4G inside it

and then add this under the volumes section in docker-compose

- ${NEXTCLOUD_ROOT}/php/memory-limit.ini:/usr/local/etc/php/conf.d/memory-limit.ini

@robertofabrizi
Copy link

robertofabrizi commented Feb 25, 2021

@fareszr That's nice, is it documented somewhere so I can get more info about it?

This is my docker container situation:

root@76abe3b16f2a:/usr/local/etc/php/conf.d# cat nextcloud.ini
memory_limit=${PHP_MEMORY_LIMIT}
upload_max_filesize=${PHP_UPLOAD_LIMIT}
post_max_size=${PHP_UPLOAD_LIMIT}
root@76abe3b16f2a:/usr/local/etc/php/conf.d# echo ${PHP_MEMORY_LIMIT}
512M

setting that file memory-limit.ini would override the env variables referenced by nextcloud.ini?

@FarisZR
Copy link
Contributor

FarisZR commented Feb 25, 2021

@fareszr That's nice, is it documented somewhere so I can get more info about it?

This is my docker container situation:

root@76abe3b16f2a:/usr/local/etc/php/conf.d# cat nextcloud.ini
memory_limit=${PHP_MEMORY_LIMIT}
upload_max_filesize=${PHP_UPLOAD_LIMIT}
post_max_size=${PHP_UPLOAD_LIMIT}
root@76abe3b16f2a:/usr/local/etc/php/conf.d# echo ${PHP_MEMORY_LIMIT}
512M

setting that file memory-limit.ini would override the env variables referenced by nextcloud.ini?

after investigating further, i think its better to just replace it directly in nextcloud.ini.
becuase as you said memory_limit.ini doesn't change the php variable

@inquam
Copy link

inquam commented Mar 29, 2022

You can simply set the environment variable PHP_MEMORY_LIMIT for your docker container (for instance "PHP_MEMORY_LIMIT=2G"). PHP_UPLOAD_LIMIT is also available to set the max size of files to be uploaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests