Question: -PHP_MEMORY_LIMIT not working in docker compose file.

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • Nextcloud Hub 8 (29.0.0)
  • Operating system and version (e.g., Ubuntu 24.04):
    • ubuntu 22.04
  • PHP version:
    • 8.2.19
  • Is this the first time you’ve seen this error? (Yes / No):
    • no
  • When did this problem seem to first start?
    • long time ago before NC28
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • Portainer Stack
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • Yes

Summary of the issue you are facing:

As requested by Josh, I repost this issue here

I use docker-compose down and docker-compose up -d with - PHP_MEMORY_LIMIT=1024M as parameter in the docker-compose.yml file in the environment section.

However, when checking using php -r "echo ini_get('memory_limit') . PHP_EOL;" it still shows 512M.

Steps to replicate it (hint: details matter!):

  1. Use docker-compose to start a NC container.
  2. With “- PHP_MEMORY_LIMIT=1024M” in the environment section of nextcloud app
  3. You will see it is still 512M when using php -r "echo ini_get('memory_limit') . PHP_EOL;"

same problem occurs when deploying on windows.

Configuration

docker-compose.yml:

version: '3'

services:
  nextcloud_db:
    container_name: nextcloud_db
    image: mariadb:latest
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      MYSQL_PASSWORD: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      MYSQL_DATABASE: nextcloud_db
      MYSQL_USER: nextcloud

  nextcloud_app:
    container_name: nextcloud
    image: nextcloud:latest
    restart: always
    ports:
      - "xxxxxxxxxxxxxxxx"
    links:
      - nextcloud_db
      - redis
    depends_on:
      - nextcloud_db
      - redis
    volumes:
      - "/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/nextcloud/config:/var/www/html/config"
      - "/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/nextcloud/data:/var/www/html/data"
      - "/root/data/docker_data/calibre/library:/var/www/html/data/Wesker/files/Calibre"
      
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=xxxxxxxxxxxxxxxxxxxxx
      - MYSQL_PASSWORD=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=root
      - MYSQL_HOST=nextcloud_db
      - NEXTCLOUD_TRUSTED_DOMAINS=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      - REDIS_HOST=redis
      - REDIS_PORT=xxxxxxxxxxxxxxxx
      - REDIS_HOST_PASSWORD=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

      - PHP_MEMORY_LIMIT=1024M

  redis:
    container_name: ncredis
    image: redis
    restart: unless-stopped
    command: redis-server --requirepass xxxxxxxxxxxxxxxx

Is this command called from within the runing docker container?

Are you aware, that you only see the memory_limit from the cli SAPI of php when running that on the console, which has nothing to do with the php-SAPI which is used by the webserver.

The Memory limit showed in the serverinfo tab of your nextcloud webinterface is the one that matters. There is no way to see that value on the console.

h.t.h.


Much and good luck,
ernolf

I wrote a php.ini with all the parameters that Nextcloud needs. Also the PHP_MEMORY memory value. The php.ini is mounted to Docker:
xxxx:/usr/local/etc/php/conf.d/php.ini

My first thoughts are:

  • Run docker compose config to see if the PHP_MEMORY_LIMIT is showing up there as expected
  • Run set | grep LIMIT inside the Nextcloud app container to see if the variable is making its way there

P.S. You’re running a very old and insecure version of Nextcloud Server (29.0.0). Please make sure you’re running up-to-date maintenance releases (29.0.10 currently).

1 Like

Thanks for reminding me about the version update! I will update it now!

Hello ernolf!

Thanks for your reply and guidance!

I have checked the web interface and it shows PHP memory limit 512 MB

Thank you.

Seems like a possible solution! Will try it myself.