Skip to content

Memory limit quite low #182

Closed
Closed

Description

@nalt

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

Activity

  1. Zogg commented on Mar 11, 2018

    @Zogg

    Bump. Having the same issue.

  2. Svarto commented on May 16, 2018

    @Svarto

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

  3. pierreozoux commented on May 16, 2018

    @pierreozoux
    Member

    What should be the limit in your opinion?

  4. jkaberg commented on May 16, 2018

    @jkaberg

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

  5. pierreozoux commented on May 17, 2018

    @pierreozoux
    Member

    Does anybody want to PR this?

  6. monreal commented on Aug 31, 2018

    @monreal

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

  7. FriedCircuits commented on Sep 1, 2018

    @FriedCircuits

    @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.

  8. monreal commented on Sep 1, 2018

    @monreal

    @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

  9. monreal commented on Sep 1, 2018

    @monreal

    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...

  10. ptrunk commented on Sep 7, 2018

    @ptrunk

    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.

  11. FriedCircuits commented on Sep 14, 2018

    @FriedCircuits

    @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.

  12. ptrunk commented on Sep 14, 2018

    @ptrunk

    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

  13. FriedCircuits commented on Sep 14, 2018

    @FriedCircuits

    @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.

  14. gladiac commented on Sep 24, 2018

    @gladiac

    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

  15. 2 remaining items

  16. FriedCircuits commented on Sep 27, 2018

    @FriedCircuits

    @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.

  17. Mr-Oca commented on Sep 27, 2018

    @Mr-Oca

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

    Did you add anything else ?

  18. FriedCircuits commented on Sep 29, 2018

    @FriedCircuits

    @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.

  19. Mr-Oca commented on Sep 29, 2018

    @Mr-Oca

    @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 //
    
  20. FriedCircuits commented on Oct 17, 2018

    @FriedCircuits

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

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

  21. lhurt commented on Oct 17, 2018

    @lhurt

    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.

  22. kosli commented on Nov 5, 2018

    @kosli

    @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

  23. ludwighurt commented on Nov 6, 2018

    @ludwighurt

    @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.

  24. J0WI commented on Nov 4, 2019

    @J0WI
    Collaborator

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

  25. MichaelUray commented on Jul 6, 2020

    @MichaelUray

    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?

  26. FarisZR commented on Feb 18, 2021

    @FarisZR
    Contributor

    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

  27. robertofabrizi commented on Feb 25, 2021

    @robertofabrizi

    @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?

  28. FarisZR commented on Feb 25, 2021

    @FarisZR
    Contributor

    @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

  29. inquam commented on Mar 29, 2022

    @inquam

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions