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:
Bump. Having the same issue.
Hi, I have similar errors being thrown in my nextcloud install, any updates / working solutions to this?
What should be the limit in your opinion?
@pierreozoux make it optional with a default (docker ENV) option?
Does anybody want to PR this?
What would be the best workaround until this is implemented? I would like to set it to 512MB
@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.
@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
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...
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.
@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.
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.
@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.
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
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.
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 ?
@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.
I already have
php_value memory_limit 512M
under both
<IfModule mod_php5.c>
and
<IfModule mod_php7.c>
Did you add anything else ?
@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.
@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 //
@kjlhgfds I found this in my custom dockerfile that might help
echo 'memory_limit=2G' > /usr/local/etc/php/conf.d/memory-limit.ini
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.
@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
@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.
A solution has been posted in https://github.com/nextcloud/docker/issues/182#issuecomment-430531984, so I'll close this.
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?
Most helpful comment
@pierreozoux make it optional with a default (docker ENV) option?