WordPress File Upload Limits

I really love WordPress…but one of the things I always struggle with is changing default values. Because there are so many, many places that you might make changes…

Today’s challenge was to increase the max upload file size so I can upload media files larger than 2MB.

I finally figured out where to make the change and how to get it to take… I think.

First off, get the output of the PHP function php_info(). The easiest way to do this is to change the index.php file in the site root directory to look like this (there may be other ways, perhaps involving plugins, to get the same information — this is just how I did it after extensive online reading):

<?php phpinfo(); ?>

Now when you navigate to the site, you’ll get a whole bunch of information about its configuration, the version of PHP it’s using, etc. What’s of interest is near the top of the first page (reformatted to show the output without HTML formatting):

Configuration File (php.ini) Path			/etc/php/8.2/fpm
Loaded Configuration File					/etc/php/8.2/fpm/php.ini
Scan this dir for additional .ini files		/etc/php/8.2/fpm/conf.d

Additional .ini files parsed

/etc/php/8.2/fpm/conf.d/10-mysqlnd.ini, 
/etc/php/8.2/fpm/conf.d/10-opcache.ini, 
/etc/php/8.2/fpm/conf.d/10-pdo.ini, 
/etc/php/8.2/fpm/conf.d/15-xml.ini, 
/etc/php/8.2/fpm/conf.d/20-calendar.ini, 
/etc/php/8.2/fpm/conf.d/20-ctype.ini, 
/etc/php/8.2/fpm/conf.d/20-curl.ini, 
/etc/php/8.2/fpm/conf.d/20-dom.ini, 
/etc/php/8.2/fpm/conf.d/20-exif.ini, 
/etc/php/8.2/fpm/conf.d/20-ffi.ini, 
/etc/php/8.2/fpm/conf.d/20-fileinfo.ini, 
/etc/php/8.2/fpm/conf.d/20-ftp.ini, 
/etc/php/8.2/fpm/conf.d/20-gd.ini, 
/etc/php/8.2/fpm/conf.d/20-gettext.ini, 
/etc/php/8.2/fpm/conf.d/20-iconv.ini, 
/etc/php/8.2/fpm/conf.d/20-imagick.ini, 
/etc/php/8.2/fpm/conf.d/20-intl.ini, 
/etc/php/8.2/fpm/conf.d/20-mbstring.ini, 
/etc/php/8.2/fpm/conf.d/20-mysqli.ini, 
/etc/php/8.2/fpm/conf.d/20-pdo_mysql.ini, 
/etc/php/8.2/fpm/conf.d/20-phar.ini, 
/etc/php/8.2/fpm/conf.d/20-posix.ini, 
/etc/php/8.2/fpm/conf.d/20-readline.ini, 
/etc/php/8.2/fpm/conf.d/20-shmop.ini, 
/etc/php/8.2/fpm/conf.d/20-simplexml.ini, 
/etc/php/8.2/fpm/conf.d/20-sockets.ini, 
/etc/php/8.2/fpm/conf.d/20-sysvmsg.ini, 
/etc/php/8.2/fpm/conf.d/20-sysvsem.ini, 
/etc/php/8.2/fpm/conf.d/20-sysvshm.ini, 
/etc/php/8.2/fpm/conf.d/20-tokenizer.ini, 
/etc/php/8.2/fpm/conf.d/20-xmlreader.ini, 
/etc/php/8.2/fpm/conf.d/20-xmlwriter.ini, 
/etc/php/8.2/fpm/conf.d/20-xsl.ini, 

In my case the file I need to change is /etc/php/8.2/fpm/php.ini. Remember to change the index.php file back to its original contents, or your site will look very odd :).

But there appears to be a catch when making the change: if you create duplicate entries in the php.ini file for a given parameter, only the last value appears to be retained. At least, I think that’s why my initial changes weren’t recognized. I’d failed to notice there were already entries for the parameters I needed to change far down in the file.

So, remember to search for a parameter before adding it.

Here are the changes I made to increase the file upload size limit (and make a few other tweaks — note that each section is often widely separated from the preceding one in the actual file):

; Maximum amount of memory a script may consume
; https://php.net/memory-limit
memory_limit = 256M

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; https://php.net/post-max-size
post_max_size = 32M

; Maximum allowed size for uploaded files.
; https://php.net/upload-max-filesize
upload_max_filesize = 16M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 40

However, it doesn’t appear to be enough to simply change the configuration values. You also need to restart whatever services use PHP. In the case of WordPress, that will either be the apache2 service or, if you’re using it, the PHP-FastCGI Process Manager. To be safe — and because I’m unclear as to how the two services interact, if at all — I restarted both:

sudo systemctl reload php8.2-fpm
sudo systemctl reload apache2

Note that the FPM service is specific to each version of PHP, so your service name may differ from mine.

One final word of caution: the order in which you reload the services may be important. I say this because I could swear I made all the changes described above and reloaded the services several times, only to find the increased values weren’t being used…until I reloaded the services in the sequence shown above and Everything Just Worked.

I hate when that happens, but there you go.

Good luck wrestling with PHP and WordPress!

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Archives
Categories