Docker: PHP Fatal error: Allowed memory size of x bytes exhausted

Created on 18 Jan 2018  路  5Comments  路  Source: nextcloud/docker

When trying to generate image previews using the occ preview:generate-all command, The following error is thrown:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 12288 bytes) in /var/www/html/lib/private/legacy/image.php on line 477

According to phpinfo() the memory_limit is set to 128M. Can this be increased? I could not find a php.ini file to change this variable. Changing it to 2048M in .htacces and .user.ini did not resolve the issue.

I am running the standard docker image (not using docker-compose).

duplicate enhancement

Most helpful comment

I fixed this problem by

  • creating custom /usr/local/etc/php/php.ini file inside container

    • putting ONLY memory_limit=1024M in new file ;)

    • checking new memory using php -r "echo ini_get('memory_limit').PHP_EOL;"

    • & that's all 馃槅

All 5 comments

I've checked all config files for a reference to the 128M memory, but I cannot locate it.
These are the config files according to php -i

Configuration File (php.ini) Path => /usr/local/etc/php
Loaded Configuration File => (none)
Scan this dir for additional .ini files => /usr/local/etc/php/conf.d
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini,
/usr/local/etc/php/conf.d/docker-php-ext-exif.ini,
/usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
/usr/local/etc/php/conf.d/docker-php-ext-intl.ini,
/usr/local/etc/php/conf.d/docker-php-ext-ldap.ini,
/usr/local/etc/php/conf.d/docker-php-ext-mcrypt.ini,
/usr/local/etc/php/conf.d/docker-php-ext-memcached.ini,
/usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini,
/usr/local/etc/php/conf.d/docker-php-ext-opcache.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pdo_pgsql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pgsql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-redis.ini,
/usr/local/etc/php/conf.d/docker-php-ext-zip.ini,
/usr/local/etc/php/conf.d/opcache-recommended.ini

However the only references to 'memory' are set in opcache-recommended and .user.ini, and I've set them both to 512M without avail.
/usr/local/etc/php/php.ini does not exist, is that a problem?

I managed to fix the memory limit by manually creating /usr/local/etc/php/php.ini in the docker container, changing it to the correct user/group, and adding this single line:
memory_limit=512M
I was then able to pre-generate my gallery previews, which was running out of memory with 128M limit.

It seems that the memory directives in _opcache-recommended.ini_ and _.user.ini_ have an effect on the _local value_ according to phpinfo, but does not edit the _master value_. Is this a bug?

Duplicate of #182

I fixed this problem by

  • creating custom /usr/local/etc/php/php.ini file inside container

    • putting ONLY memory_limit=1024M in new file ;)

    • checking new memory using php -r "echo ini_get('memory_limit').PHP_EOL;"

    • & that's all 馃槅

Another method, that I found a bit more reliable (because it takes precedent over other php.ini settings,) is to create a custom config file.

  1. Create a file on your host machine. In my case, I was updating the max upload size: /Users/[username]/docker/php/uploads.ini

  2. Add custom settings to your new file:

max_execution_time=600
memory_limit=-1
upload_max_filesize = 64M

... any other settings
  1. Inside your docker-compose.yml file, add this to the volumes section of the desired container: /Users/[username]/docker/php/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

  2. Restart your docker container and it should show the new settings.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raimund-schluessler picture raimund-schluessler  路  3Comments

pr4xx picture pr4xx  路  4Comments

nthack picture nthack  路  3Comments

DisasteR picture DisasteR  路  3Comments

SQGE picture SQGE  路  3Comments