New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase PHP file upload limit #10

Closed
damongant opened this Issue Aug 21, 2014 · 36 comments

Comments

Projects
None yet
@damongant

damongant commented Aug 21, 2014

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

@yosifkit

This comment has been minimized.

Member

yosifkit commented Aug 22, 2014

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?

@tianon

This comment has been minimized.

Member

tianon commented Aug 23, 2014

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.

@tianon

This comment has been minimized.

Member

tianon commented Aug 23, 2014

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?

@damongant

This comment has been minimized.

damongant commented Sep 1, 2014

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

@Nxir

This comment has been minimized.

Nxir commented Oct 9, 2014

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

@korjavin

This comment has been minimized.

korjavin commented Dec 7, 2014

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

@dbxt

This comment has been minimized.

dbxt commented Dec 14, 2014

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.

@darwingr

This comment has been minimized.

darwingr commented Jan 30, 2015

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
@clonn

This comment has been minimized.

clonn commented Apr 1, 2015

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
@pierreozoux

This comment has been minimized.

pierreozoux commented Jul 19, 2015

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!

@zx1986

This comment has been minimized.

zx1986 commented Sep 15, 2015

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

@JulianKingman

This comment has been minimized.

JulianKingman commented Oct 19, 2015

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?

@darwingr

This comment has been minimized.

darwingr commented Oct 21, 2015

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

@kop

This comment has been minimized.

kop commented Dec 5, 2015

+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.

@mattjonesorg

This comment has been minimized.

mattjonesorg commented Jan 23, 2016

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.

@vyscond

This comment has been minimized.

vyscond commented Jun 23, 2016

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

@juanpablocs

This comment has been minimized.

juanpablocs commented Jun 27, 2016

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
@Chaz6

This comment has been minimized.

Chaz6 commented Aug 19, 2016

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

@vyscond

This comment has been minimized.

vyscond commented Aug 19, 2016

@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
@m-pawelczyk

This comment has been minimized.

m-pawelczyk commented Jan 6, 2017

@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

@damongant

This comment has been minimized.

damongant commented Jan 6, 2017

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!

@nebuchar

This comment has been minimized.

nebuchar commented Feb 25, 2017

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

nebuchar/wordpress-unlimited

@stcalica

This comment has been minimized.

stcalica commented Mar 16, 2017

@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?

@damongant

This comment has been minimized.

damongant commented Mar 16, 2017

@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.

@vyscond

This comment has been minimized.

vyscond commented Mar 16, 2017

@stcalica post:

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

This comment has been minimized.

stcalica commented Mar 23, 2017

@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.

@matteo-bombelli

This comment has been minimized.

matteo-bombelli commented Apr 23, 2017

Thank you!

Please add this to the readme.

@tremy0207

This comment has been minimized.

tremy0207 commented Sep 13, 2017

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?

@vyscond

This comment has been minimized.

vyscond commented Sep 14, 2017

@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 👍

@tremy0207

This comment has been minimized.

tremy0207 commented Sep 20, 2017

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

@zx1986

This comment has been minimized.

zx1986 commented Sep 29, 2017

@tremy0207 老哥,你想咋整啊?

@damongant

This comment has been minimized.

damongant commented Sep 30, 2017

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

@FroeMic

This comment has been minimized.

FroeMic commented Apr 2, 2018

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!

@Hbehboodi

This comment has been minimized.

Hbehboodi commented Apr 21, 2018

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?

@tianon

This comment has been minimized.

Member

tianon commented Apr 23, 2018

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/
@tianon

This comment has been minimized.

Member

tianon commented Apr 24, 2018

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment