Skip to content
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
acuteaura opened this issue Aug 21, 2014 · 40 comments
Closed

Increase PHP file upload limit #10

acuteaura opened this issue Aug 21, 2014 · 40 comments
Labels

Comments

@acuteaura
Copy link

@acuteaura acuteaura 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
Copy link
Member

@yosifkit 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
Copy link
Member

@tianon 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
Copy link
Member

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

@acuteaura
Copy link
Author

@acuteaura acuteaura commented Sep 1, 2014

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

@Nxir
Copy link

@Nxir 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
Copy link

@korjavin korjavin commented Dec 7, 2014

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

@dbxt
Copy link

@dbxt 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
Copy link

@darwingr 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
Copy link

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

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

@zx1986 zx1986 commented Sep 15, 2015

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

@JulianKingman
Copy link

@JulianKingman 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
Copy link

@darwingr darwingr commented Oct 21, 2015

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

@kop
Copy link

@kop 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
Copy link

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

@ramonmoraes8080
Copy link

@ramonmoraes8080 ramonmoraes8080 commented Jun 23, 2016

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

@juanpablocs
Copy link

@juanpablocs 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
Copy link

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

@ramonmoraes8080
Copy link

@ramonmoraes8080 ramonmoraes8080 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
Copy link

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

@acuteaura
Copy link
Author

@acuteaura acuteaura 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
Copy link

@nebuchar 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
Copy link

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

@acuteaura
Copy link
Author

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

@ramonmoraes8080
Copy link

@ramonmoraes8080 ramonmoraes8080 commented Mar 16, 2017

@stcalica post:

  1. your full composer file.
  2. OS
  3. full path to the compose file
@matteo-bombelli
Copy link

@matteo-bombelli matteo-bombelli commented Apr 23, 2017

Thank you!

Please add this to the readme.

@tremy0207
Copy link

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

@ramonmoraes8080
Copy link

@ramonmoraes8080 ramonmoraes8080 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
Copy link

@tremy0207 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
Copy link

@zx1986 zx1986 commented Sep 29, 2017

@tremy0207 老哥,你想咋整啊?

@acuteaura
Copy link
Author

@acuteaura acuteaura commented Sep 30, 2017

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

@FroeMic
Copy link

@FroeMic 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
Copy link

@Hbehboodi 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
Copy link
Member

@tianon 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
Copy link
Member

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

@NaveenKharwar
Copy link

@NaveenKharwar NaveenKharwar commented Dec 13, 2018

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

@adriatic
Copy link

@adriatic adriatic commented Feb 13, 2019

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.

@sadesarrollo
Copy link

@sadesarrollo sadesarrollo commented Jun 27, 2019

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'

@tianon
Copy link
Member

@tianon tianon commented Jul 3, 2019

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

@docker-library docker-library locked as resolved and limited conversation to collaborators Jul 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.