Kyle Calica-St
Kyle Calica-St

Reputation: 2943

Wordpress Docker won't increase upload limit

I am trying to increate the upload limit of my Dockerized Wordpress instance to 150M.

[filename] exceeds the maximum upload size for this site.

I have created an uploads.ini file and attached it by volume to the instance. Yet I still can't get the Wordpress media uploader to increase it's limit.

Docker-compose.yml:

version: '2'
services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: password1
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: password1

   wordpress:
     depends_on:
       - db
     build: ./wordpress
     ports:
       - "8085:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_PASSWORD: password1
     volumes: 
       - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini 
volumes:
    db_data:

uploads.ini:

file_uploads = On
memory_limit = 500M
upload_max_filesize = 500M
post_max_size = 500M
max_execution_time = 600

Docker inspect on container:

[
    {
        "Id": "8edc91a51bf8480edc927de2fa5c16624ac43a7beb58c109cd771a143f67746f",
        "Created": "2017-03-15T23:47:54.480206792Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "apache2-foreground"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 15956,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2017-03-16T17:46:30.075247017Z",
            "FinishedAt": "2017-03-16T17:46:29.700791339Z"
        },
        "Image": "sha256:cfe94722592e66629527d7fc1546174916c758c6945eb9911506077e76c4d00e",
        "ResolvConfPath": "/var/lib/docker/containers/8edc91a51bf8480edc927de2fa5c16624ac43a7beb58c109cd771a143f67746f/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/8edc91a51bf8480edc927de2fa5c16624ac43a7beb58c109cd771a143f67746f/hostname",
        "HostsPath": "/var/lib/docker/containers/8edc91a51bf8480edc927de2fa5c16624ac43a7beb58c109cd771a143f67746f/hosts",
        "LogPath": "/var/lib/docker/containers/8edc91a51bf8480edc927de2fa5c16624ac43a7beb58c109cd771a143f67746f/8edc91a51bf8480edc927de2fa5c16624ac43a7beb58c109cd771a143f67746f-json.log",
        "Name": "/edgeofrevolt_wordpress_1",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": [
            "8efe40659ebd3e44b17d45f1dd2aac20f12e13a4513e41520d6c2a1b1f01aa08"
        ],
        "HostConfig": {
            "Binds": [
                "/root/NginxDockerProxyPass/edgeofrevolt/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini:rw",
                "374db2645434a23b92074b6d95935361948397519f2d5a531986bb925ceb0f53:/var/www/html:rw"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "edgeofrevolt_default",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "8085"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "always",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": [],
            "CapAdd": null,
            "CapDrop": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Name": "aufs",
            "Data": null
        },
        "Mounts": [
            {
                "Source": "/root/NginxDockerProxyPass/edgeofrevolt/uploads.ini",
                "Destination": "/usr/local/etc/php/conf.d/uploads.ini",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Name": "374db2645434a23b92074b6d95935361948397519f2d5a531986bb925ceb0f53",
                "Source": "/var/lib/docker/volumes/374db2645434a23b92074b6d95935361948397519f2d5a531986bb925ceb0f53/_data",
                "Destination": "/var/www/html",
                "Driver": "local",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "8edc91a51bf8",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "affinity:container==6797730d5702955f114fd260628b82615aa7702d0cafae7dae456b1806009437",
                "WORDPRESS_DB_HOST=db:3306",
                "WORDPRESS_DB_PASSWORD=p0kem0n2468Y",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "PHPIZE_DEPS=autoconf \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkg-config \t\tre2c",
                "PHP_INI_DIR=/usr/local/etc/php",
                "APACHE_CONFDIR=/etc/apache2",
                "APACHE_ENVVARS=/etc/apache2/envvars",
                "PHP_EXTRA_BUILD_DEPS=apache2-dev",
                "PHP_EXTRA_CONFIGURE_ARGS=--with-apxs2",
                "PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2",
                "PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2",
                "PHP_LDFLAGS=-Wl,-O1 -Wl,--hash-style=both -pie",
                "GPG_KEYS=0BD78B5F97500D450838F95DFE857D9A90D90EC1 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3",
                "PHP_VERSION=5.6.30",
                "PHP_URL=https://secure.php.net/get/php-5.6.30.tar.xz/from/this/mirror",
                "PHP_ASC_URL=https://secure.php.net/get/php-5.6.30.tar.xz.asc/from/this/mirror",
                "PHP_SHA256=a363185c786432f75e3c7ff956b49c3369c3f6906a6b10459f8d1ddc22f70805",
                "PHP_MD5=68753955a8964ae49064c6424f81eb3e",
                "WORDPRESS_VERSION=4.7.2",
                "WORDPRESS_SHA1=7b687f1af589c337124e6247229af209ec1d52c3"
            ],
            "Cmd": [
                "apache2-foreground"
            ],
            "Image": "edgeofrevolt_wordpress",
            "Volumes": {
                "/usr/local/etc/php/conf.d/uploads.ini": {},
                "/var/www/html": {}
            },
            "WorkingDir": "/var/www/html",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "com.docker.compose.config-hash": "da7c1855141bc762874ddd4734f2b062556a041750ff48a3cfa3954bb7dfed6c",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.oneoff": "False",
                "com.docker.compose.project": "edgeofrevolt",
                "com.docker.compose.service": "wordpress",
                "com.docker.compose.version": "1.8.1"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "ceec8d1498a6988b4cc56ad10afa5cf87e0670d030460efbd26bd5ace185a375",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "8085"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/ceec8d1498a6",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "edgeofrevolt_default": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "wordpress",
                        "8edc91a51bf8"
                    ],
                    "NetworkID": "89bde3d402cc2fe938279c30415cc2947f92205e610dff1acba69101440b90e7",
                    "EndpointID": "916db2fab99a1637aef87aa1f05fb702fb9b6d3692bf04a9bf46bf122fe9e990",
                    "Gateway": "172.23.0.1",
                    "IPAddress": "172.23.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:17:00:03"
                }
            }
        }
    }
]

EDIT: there was a typo in 'upload_max_filesize'

Upvotes: 92

Views: 78625

Answers (13)

What many have not thought of is that the uploads.ini requires the correct authorization.

Especially with dockremap user e.G.

chown -R 100000:100000 uploads.ini

Otherwise, this is exactly what happens in the container:

root@c5cf31571ea5:/var/www/html# cat /usr/local/etc/php/conf.d/uploads.ini
cat: /usr/local/etc/php/conf.d/uploads.ini: **Permission denied**

Upvotes: 0

Ayaks Telomonid
Ayaks Telomonid

Reputation: 11

version: '2'
services:
  db:
    image: mysql:latest
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password1
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: password1
    networks:
      - mynetwork

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "32788:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_PASSWORD: password1
    volumes:
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
      - ./wordpress:/var/www/html
    networks:
      - mynetwork

  php:
    image: php:8.0-fpm
    volumes:
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
    environment:
      PHP_MEMORY_LIMIT: 500M
    networks:
      - mynetwork

  ftp:
    image: stilliard/pure-ftpd:hardened
    environment:
      PUBLICHOST: "localhost"
      FTP_USER_NAME: "ftpuser"
      FTP_USER_PASS: "ftppassword"
      FTP_USER_HOME: "/var/www/html"
      FTP_PASSIVE_PORTS: "30000:30009"  # Указание диапазона пассивных портов
    volumes:
      - ./wordpress:/var/www/html
    ports:
      - "21:21"
      - "30000-30009:30000-30009"
    networks:
      - mynetwork

networks:
  mynetwork:

volumes:
  db_data:
  ftpdata:

Upvotes: 1

Mikhail Mamaev
Mikhail Mamaev

Reputation: 29

To increase upload limit you are to add these lines to docker-compose.yml file to wordpress environment section:

- PHP_POST_MAX_SIZE=150M

- PHP_UPLOAD_MAX_FILESIZE=150M

- PHP_MAX_EXECUTION_TIME=600

and exec commands:

> docker-compose down

> docker-compose up -d

Upvotes: 0

EtwinCorp
EtwinCorp

Reputation: 115

I didn't create an 'uploads.ini' file but an 'upload.ini' file and added it, as mentioned, alongside with the docker-compose.yaml file. then I did bind it as mentioned in the docker-compose.yaml file :

volumes:
  - ./upload.ini:/usr/local/etc/php/conf.d/uploads.ini

and then I ran docker compose up --build and It worked !!

Upvotes: 2

Menilik Eshetu
Menilik Eshetu

Reputation: 11

The best answer is if you are just installing/uploading a compress file like xxx.zip file this error will pop up and you can not install it any plugin or theams so that you have to go to that file in the directory and open that xxx.zip file and delete unnecessary file for my case there is .git file which is 1.7 MB in size i delete it and it worked just fine. Hope this will solve your problem

Upvotes: -2

gLoMeR
gLoMeR

Reputation: 1

volumes: - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

This doesn't work. It creates an empty folder "uploads.ini". (/data/compose/17/uploads.ini/) I create a file inside it (/data/compose/17/uploads.ini/uploads.ini) but nothing happens. It remains 2M file size limit.

Upvotes: -1

F1Linux
F1Linux

Reputation: 4373

This solution solves the problem via a Dockerfile:

I modified my docker-compose.yml in the following way when I brushed up against the PHP file upload limit issue:

First I created uploads.ini:

file_uploads = On
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600

Next I created Dockerfile-php:

FROM wordpress:5.8.2
COPY ./uploads.ini /usr/local/etc/php/conf.d

Finally, I added build config in the wordpress part of docker-compose.yml to reference Dockerfile-php which in turn referenced uploads.ini:

  wordpress:
    build:
      context: .
      dockerfile: Dockerfile-php
    depends_on:
      - db
    image: wordpress:5.8.2
   <snippity snip>

Then, while in the docker-compose directory with all my files:

docker rm [containerName]
docker-compose build --no-cache
docker-compose up -d

(I know --no-cache in the build command above is redundant if we've already deleted the legacy container(s); just good practice to ensure we always read the latest changes)

I was now able to successfully upload the files previously failing due to the PHP limit restriction.

Upvotes: 4

ahmed534
ahmed534

Reputation: 281

Just add these two lines to then end of your .htaccess file :

php_value upload_max_filesize 500M
php_value post_max_size 500M

You don't even need to restart the container

Upvotes: 28

smaqsood
smaqsood

Reputation: 1889

it worked for me as follows: i created uploads.ini alongside of docker-compose.yml with following lines. this is exactly how it stated in fist post.

file_uploads = On
memory_limit = 500M
upload_max_filesize = 500M
post_max_size = 500M
max_execution_time = 600

after this i added

volumes: 
   - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

to my .yml file as it states in first post.

after this i had to delete the container/images (basically start from scratch):

docker stop [image name]
docker rm [image name]
docker image rm [image name]

some places i end up using ID insted of image name. name or ID basically you have to stop, remove container and image. bottom line is start from scratch with additional line in your .yml file as describe in first post. remember, you'll lose all your wp work. now run

docker-compose up -d --build

upload limit should be increased now. i was able to upload my new bigger theme after this change. no more upload file size error. only question is if you need to increase this upload size limit in the middle of your work then how would you do this?...

Upvotes: 157

Stepan
Stepan

Reputation: 569

I prefer to adjust .htaccess for my own workflow. Last 2 lines are what I added

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

php_value upload_max_filesize 500M
php_value post_max_size 500M

then restart

docker-compose down --volumes
docker-compose up -d

Enjoy )

Upvotes: 46

Alexander Ezhov
Alexander Ezhov

Reputation: 41

The best option would be to execute the command:

docker-compose down && docker-compose up -d --build

docker-compose kill, in this case the process itself is killed, this is not entirely correct.

Upvotes: 2

Kyle Calica-St
Kyle Calica-St

Reputation: 2943

I discovered my problem.

docker-compose kill will kill a container but rebuild it from a cache. Meaning no changes to my files were taking place.

Use docker-compose up -d --build

Upvotes: 24

user7832953
user7832953

Reputation: 29

There is a typo in your uploads.ini

upload_max_fileszie => upload_max_filesize

Upvotes: 1

Related Questions