`Out of memory` error in PHPMyAdmin within Laravel Sail Docker environment

419 views Asked by At

I'm trying to run phpMyAdmin in a Docker environment using Laravel Sail, but I've been encountering an Out of memory error for a few days now. I'm not sure where to check and change. The specific error message I'm seeing is:

When I accessed http://localhost:8888/

Fatal error: Out of memory (allocated 2097152 bytes) (tried to allocate 81920 bytes) in /var/www/html/vendor/composer/autoload_static.php on line 421

Then reloaded.

PHP Fatal error: Out of memory (allocated 2097152 bytes) (tried to allocate 65536 bytes) in /var/www/html/vendor/composer/autoload_real.php on line 33

What I've tried:

1. Restart sail I executed $ sail restart.

2. Rebuild with no cache I executed $ sail build --no-cache and $ sail up -d.

3. Set the env PHP_MEMORY_LIMIT: 1G of phpmyadmin on docker-compose.yml

I executed $ sail restart. It still shows the same error.

Ref: dockerhub phpmyadmin

4. Set phpmyadmin-misc.ini

I created ./phpmyadmin/phpmyadmin-misc.ini and ./phpmyadmin/sessions. I also added these files as volumes in docker-compose.yml.

Context of volumes in docker-compose.yml

volumes:
  - ./phpmyadmin/sessions:/sessions
  - ./phpmyadmin-misc.ini:/usr/local/etc/php/conf.d/phpmyadmin-misc.ini

Context of phpmyadmin-misc.ini

allow_url_fopen = Off
max_execution_time = 600
memory_limit = 64M
post_max_size = 64M
upload_max_filesize = 64M

Ref: A site about memory limit written in Ja

5. Set deploy.resouces.limits and reservations

Context of deploy in docker-compose.yml

phpmyadmin:
        image: phpmyadmin/phpmyadmin:5.2.1
        deploy:
            resources:
                limits:
                    cpus: '0.50'
                    memory: 50M
                reservations:
                    cpus: '0.25'
                    memory: 20M

Ref: Compose file version 3 reference

6. Set the memory_limit in php.ini to 2048M

  1. $ sail exec phpmyadmin bash.

  2. $ echo "<?php phpinfo(); ?>" > info.php

  3. Access http://localhost:8888/info.php and see php.ini location.

    Configuration File (php.ini) Path /usr/local/etc/php

  4. $ cd /usr/local/etc/php

  5. $ ls

    conf.d php.ini-development php.ini-production

  6. $ cp php.ini-production php.ini

  7. $ apt-get update && apt-get install vim

  8. Set memory_limit=2048M in php.ini

  9. $ exit and $ sail restart

The error persists.

Environment:

  • Mac M2, 2022 memory 16G, OS Sonoma 14.0
  • Docker version 20.10.8, build 3967b7d
  • Docker resource settings CPUs: 4, Memory: 3.00 GB, Swap: 1 GB, Disk image size: 59.6 GB (27.5 GB used)
  • Running on Docker using Laravel Sail
  • "laravel/sail": "^1.22",
  • PHPMyAdmin image used: phpmyadmin/phpmyadmin

docker-compose.yml

version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.2
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.2/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'
            - '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
            IGNITION_LOCAL_SITES_PATH: '${PWD}'
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - mailpit
    mysql:
        image: 'mysql/mysql-server:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ROOT_HOST: '%'
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 1
        volumes:
            - 'sail-mysql:/var/lib/mysql'
            - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
        networks:
            - sail
        healthcheck:
            test:
                - CMD
                - mysqladmin
                - ping
                - '-p${DB_PASSWORD}'
            retries: 3
            timeout: 5s
    mailpit:
        image: 'axllent/mailpit:latest'
        ports:
            - '${FORWARD_MAILPIT_PORT:-1025}:1025'
            - '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025'
        networks:
            - sail
    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        links:
            - mysql:mysql
        ports:
            - 8888:80
        environment:
            MYSQL_USERNAME: '${DB_USERNAME}'
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            PMA_HOST: mysql
        networks:
            - sail
networks:
    sail:
        driver: bridge
volumes:
    sail-mysql:
        driver: local

I would greatly appreciate any suggestions on potential configurations, changes, or other troubleshooting methods related to this error. Thank you in advance!

I attempted to run phpMyAdmin within a Docker environment using Laravel Sail. As part of the setup, I made several configurations to adjust the memory limits.

1

There are 1 answers

1
Jeyhun Rashidov On BEST ANSWER

Before diving into configurations, ensure that the physical system (your Mac) has enough free memory available. If you have enough space, open Docker Desktop, go to Preferences/Settings, and choose Resources. Under Memory, try increasing the memory allocated to Docker. Currently, you've set it to 3.00 GB. Given your system has 16GB, you can safely allocate more (like 6GB or 8GB) if needed.

If these don't help you can try directly setting the memory limit in your docker-compose.yml:

phpmyadmin:
    image: phpmyadmin/phpmyadmin
    mem_limit: 1g
    ...