Wordpress: Increase PHP file upload limit

Created on 21 Aug 2014  ·  40Comments  ·  Source: docker-library/wordpress

If you're going to run on docker, the last thing you should be concerned with is too big files being uploaded.

Request

Most helpful comment

Found something that seems to work for me. I've created an __uploads.ini__ file with the following contents:

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

Then I added the ini to the appropriate conf.d path I found in the phpinfo (/usr/local/etc/php/conf.d/):

docker run --name some-wordpress --link=some-mysql:mysql -e WORDPRESS_DB_NAME=some_wordpress -v /var/docker/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini -v /var/docker/phpinfo.php:/var/www/html/phpinfo.php -p 8081:80  -d wordpress

My wordpress upload limit is sitting at 64M now which is plenty for what I need. Hope this helps someone else.

All 40 comments

As much as I dislike running into php's file upload limits, I am not sure that we want to change from the default coming from apache and php. We could add an example for changing this and other php.ini related variables.

/cc @tianon thoughts?

Yeah, I'm also wary of this, especially since Docker doesn't actually have explicit container quota support (which would be a whole different story, but still only half the story). This might be something that's changed often enough that it warrants an environment variable for custom tweaking, but I'm +1 on keeping the default as untouched from upstream.

When you change the value of this in php.ini, isn't there some Wordpress setting you have to tweak to get it to actually pick it up correctly, or has that been fixed?

@tianon Not that I'd know, didn't have to do anything on my instances.

docker run --name dev-wordpress --link dev-mysql:mysql -v ~/wordpressDof/config/php.ini:/etc/php5/apache2/php.ini -p 80:80 -d wordpress

@Nxir
I saw in debug :
Configuration File (php.ini) Path /usr/local/etc/php

Found something that seems to work for me. I've created an __uploads.ini__ file with the following contents:

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

Then I added the ini to the appropriate conf.d path I found in the phpinfo (/usr/local/etc/php/conf.d/):

docker run --name some-wordpress --link=some-mysql:mysql -e WORDPRESS_DB_NAME=some_wordpress -v /var/docker/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini -v /var/docker/phpinfo.php:/var/www/html/phpinfo.php -p 8081:80  -d wordpress

My wordpress upload limit is sitting at 64M now which is plenty for what I need. Hope this helps someone else.

There isn't a default php.ini file created with the base image that is used for wordpress.
The following 2 options should work but I prefer the second (B) for my own workflow and deviates less from upstream (docker-library/wordpress).

A) Add the following 2 lines to your wordpress Dockerfile:

RUN touch /usr/local/etc/php/conf.d/uploads.ini \
    && echo "upload_max_filesize = 10M;" >> /usr/local/etc/php/conf.d/uploads.ini

However, on the docker registry page they recommend adding a custom php.ini to /usr/local/lib.

B) Set the limits with your .htaccess file thats in your wordpress data directory.
In my case I have this directory under version control anyways, as would most.
The bottom 2 lines are what I added to my .htaccess on a brand new wordpress install via docker:

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

php_value post_max_size 24M
php_value upload_max_filesize 8M

just like @dbxt says,

create uploads.ini then, content is

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

use fig.yml solution, to replace uploads.ini

db:
  image: mysql:latest
  environment:
    MYSQL_ROOT_PASSWORD: "PASSWORD-HERE"

wordpress:
  image: wordpress:latest
  ports:
    - "80:80"
  links:
    - db:mysql
  volumes:
    - uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

I think it is clear that this is not an issue with the image. The image should be as close as possible to the defaults. For specific configuration, please mount your configuration or create your own image based on this one.

Can we close the issue now?

Thanks!

@clonn WOW! it works prefect!
@darwingr and .htaccess works too.

A session variable would be helpful, as mounting local volumes is not portable from one host to another.

@darwingr I'm interested in the .htaccess method, how would you go about that using a WP data container?

@JulianKingman you can use fig (docker-compose) as clonn did above

+1 for creating an environment variable for configuring this.

All volume-related options are only suitable for local development.
For production, the only option is to create custom Docker image that is based on the official image. Doing this just to change upload max size? Seriously?

Or, even better, there could be a script that will parse PHP_INI_<init setting> environment vars and set them. This will eliminate the need in tons of custom WP images and will save tons of time for developers.

If you are running into this issue, I've created a docker file with the uploads.ini file specified above that is available here: https://hub.docker.com/r/mattjonestechnology/wordpress/. This has worked well with me deployed to a Kubernetes cluster.

@clonn answer should have a special spot on the README.md (IMHO)

direct on dockerfile

#upload
RUN echo "file_uploads = On\n" \
         "memory_limit = 500M\n" \
         "upload_max_filesize = 500M\n" \
         "post_max_size = 500M\n" \
         "max_execution_time = 600\n" \
         > /usr/local/etc/php/conf.d/uploads.ini

How would this be done in docker-compose.yml? I am in support of setting this at run-time using an environment variable.

@Chaz6 just like this

services:
  db:
    image: mariadb:10.1
    command: mysqld --innodb-buffer-pool-size=64M
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
  wordpress:
    image: wordpress
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    depends_on:
      - db
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
      - ./my-wordpress-theme:/var/www/html/wp-content/themes/my-wordpress-theme

@dbxt why did you attached phpinfo.php to configuration docker run? I have done it and phpinfo.php is a directory which is empty. uploads.ini work perfect for me and uploads limits increased.

docker run -e WORDPRESS_DB_PASSWORD=password -d --name wordpress --link wordpressdb:mysql -p 8080:80 -v /home/mp/docker/wp:/var/www/html -v /home/mp/docker/wp_conf/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini wordpress

Hey @m-pawelczyk - it seems you confused the purpose of that mount. Docker can mount a single file to a container too, this is not a directory. It is not needed to change the PHP settings, but useful to test them (via phpinfo()), don't use that mount on a container you're not just testing your extended configuration on!

Hi, I just created an image with the configuration from @juanpablocs, you can find it here:

nebuchar/wordpress-unlimited

@vyscond I added that to my docker-compose.yml but when I look at media add new upload it still says: Maximum upload file size: 2 MB.

Any reason why? do i need to restart wordpress/docker?

@stcalica

  • Did you add an uploads.ini to the same directory docker-compose.yml is in?
  • Did you docker-compose restart - because yes, the container must be recreated to add a mount. Thankfully compose can handle the heavy lifting for you.

If those don't work, post docker inspect output so we have something to work with.

@stcalica post:

  1. your full composer file.
  2. OS
  3. full path to the compose file

@damongant @vyscond so I've tried a bunch of different things and still couldn't get it.
I made this stackoverflow post to consolidate all my info I felt bad about spamming this thread.

feel free to reply in here or on that post. either one. i've exhausted most of the suggestions here.

Thank you!

Please add this to the readme.

For those of us who just desire a straight answer. Can anyone of the experts provide a simple answer. How to increase the upload size in php.ini?

@tremy0207 You basically need to override the following file /usr/local/etc/php/conf.d/uploads.ini. The easiest way is to just pass an external file if the desired to the uploads.ini to inside of the container:

  • Simple container
    docker run -v /home/someuser/mywordpress_project/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini wordpress

  • Composer

services:
  db:
    image: mariadb:10.1
    command: mysqld --innodb-buffer-pool-size=64M
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
  wordpress:
    image: wordpress
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    depends_on:
      - db
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini  # <- right here, boi!!!
      - ./my-wordpress-theme:/var/www/html/wp-content/themes/my-wordpress-theme

Notes

If you're working on a docker-composer environment please do not forget to rebuild you container after your edit: docker-compose up -d --build 👍

Thanks for your suggestion. However, I am new to Docker. Can you provide this information for a novice? Thanks

@tremy0207 老哥,你想咋整啊?

Can you move the support/chatter someplace else? Thanks.

I refactored the official example from https://docs.docker.com/compose/wordpress/ to allow for easy configuration of a php.ini file to configure the upload_max_filesize.

Have a look here: https://github.com/FroeMic/Docker-Compose-Wordpress

I hope it helps!

I am using this image via kitematic . How can I increase the upload size using kitematic?

Also if we increase the size via a local file so when we want to publish from local workstation to production we have to copy all these configs too. Is there any better solutions? For example some environment variables? or I think using "RUN echo ..." command is better that adding a volume for upload.ini but I do not know how can I run this command using kitematic. Does someone have any idea?

To persist your changes, create a short Dockerfile and build the configuration into the image instead and deploy _that_:

FROM wordpress:php7.2-apache
COPY uploads.ini /usr/local/etc/php/conf.d/

Closing given that this is fairly well-discussed and we lack an official recommendation from WordPress upstream on what an appropriate value for this setting should be (and the current value is the default coming directly from PHP upstream).

There isn't a default php.ini file created with the base image that is used for wordpress.
The following 2 options should work but I prefer the second (B) for my own workflow and deviates less from upstream (docker-library/wordpress).

A) Add the following 2 lines to your wordpress Dockerfile:

RUN touch /usr/local/etc/php/conf.d/uploads.ini \
    && echo "upload_max_filesize = 10M;" >> /usr/local/etc/php/conf.d/uploads.ini

However, on the docker registry page they recommend adding a custom php.ini to /usr/local/lib.

B) Set the limits with your .htaccess file thats in your wordpress data directory.
In my case I have this directory under version control anyways, as would most.
The bottom 2 lines are what I added to my .htaccess on a brand new wordpress install via docker:

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

php_value post_max_size 24M
php_value upload_max_filesize 8M

Thank You <3

Check the thread Increase PHP file upload limit, for the continuation of this discussion. There is a solution in the form of the YAML file for the composer here.

How are you supposed to change to pm = static?

Every time I try mapping a file containing this configuration like this:

volumes:
- ${PHP_CONF_DIR:-./php}/pool.d:/usr/local/etc/php-fpm.d

I get an error saying:

[27-Jun-2019 18:11:30] ERROR: [/usr/local/etc/php-fpm.d/my-extra.conf:1] unknown entry 'pm'

@sadesarrollo that setting is "per-pool", so you want your file to start with [www]

In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

Was this page helpful?
0 / 5 - 0 ratings