Search code examples
phplinuxdockerdocker-composelamp

upload size increase not working (LAMP Docker)


cant upload +2m files

docker compose

version: "3.7"
services:
  web-server:
    build:
      dockerfile: php.Dockerfile
      context: .
    restart: always
    volumes:
      - "./html/:/var/www/html/"
    ports:
      - "8080:80"
  mysql-server:
    image: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: rise
    volumes:
      - mysql-data:/var/lib/mysql

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    restart: always
    environment:
      PMA_HOST: mysql-server
      PMA_USER: root
      PMA_PASSWORD: rise
      UPLOAD_LIMIT: 500M
    ports:
      - "8444:80"
volumes:
  mysql-data:

Php.dockerfile

FROM php:8.0-apache

RUN a2enmod rewrite

RUN apt-get update && apt-get install -y git unzip zip


COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions gd pdo_mysql bcmath zip intl opcache MySQLi

COPY --from=composer:2.0 /usr/bin/composer /usr/local/bin/composer

if you see the upload limit is 500mb but the php site dont want upload 2+mb files

follow guidens and add env but is not working. dont finde the php.ini or the .htaccess

can you help me please

thx


Solution

  • It looks like you added ENV var to the PhpAdmin container config only. But to upload file on site, the 'web-server' container is involved instead, right?

    So you need to update the php.ini file of the 'web-server' container.

    This can be done by mapping custom php.ini file from host to container. Values in this file will override any existing values. Add this lines to your docker-compose.yml, under the web-server:

    volumes:
      - ./path/to/the/local/custom-php.ini:/path/to/the/folder/where/php/scans/additional/ini-files/custom-php.ini
    

    Then create ./path/to/the/local/custom-php.ini (path can be any) file and put there this line:

    upload_max_filesize = 500M
    

    After this you need to determine /path/to/the/folder/where/php/scans/additional/ini-files/ folder. This can be done by running this command:

    docker exec web-server php --ini
    

    In the output you will see all the ini files used by php, and there will should be smth like "Scan for additional .ini files in: {path to folder}". This is the folder where you should map your custom-php.ini file, i.e. you need to replace /path/to/the/folder/where/php/scans/additional/ini-files/ with this path.