Skip to main content

By default the maximum file upload size is set to 2MB.  It is not a Drupal issue, instead a php issue as upload_max_filesize is set in your php configuration (php.ini file).  Therefore it is a server-side configuration. If you have access to the php configuration file, I would recommend to make the changes directly in it.  Yet, on some occasions you cannot access the server configuration (on a shared hosting, for instance) and if you wish to alter some of your server configuration you have to use the .htaccess file (see more info here)

 

Looking at ways to solve

1. Make the changes directly into php.ini (find upload_max_filesize and change its value).

2. use the .htaccess if you don't have access to the php.ini file. (The upload module does not make anything else than altering the .htaccess file).

 

How to investigate this error

Global response

How to find the php.ini in use?  In shell run the command:

php -i

This will output the phpinfo() data... displaying something like

PHP Version => 7.4.19

System => Linux ip-10-0-2-168.ap-southeast-2.compute.internal 4.14.232-176.381.amzn2.x86_64 #1 SMP Wed May 19 00:31:54 UTC 2021 x86_64

Build Date => May 13 2021 22:36:33

Server API => Command Line Interface

Virtual Directory Support => disabled

Configuration File (php.ini) Path => /etc

Loaded Configuration File => /etc/php.ini

Scan this dir for additional .ini files => /etc/php.d

 

Do a search for php.ini to see the result being something like:

Configuration File (php.ini) Path => /etc

or

Configuration File (php.ini) Path => /etc

Loaded Configuration File => /etc/php.ini

 

Using --ini

Another approach is to run the command

php --ini

That will provide a response similar to

Configuration File (php.ini) Path: /opt/plesk/php/8.2/etc
Loaded Configuration File:         /var/www/vhosts/{domain}/etc/php.ini
Scan for additional .ini files in: /opt/plesk/php/8.2/etc/php.d
Additional .ini files parsed:
/opt/plesk/php/8.2/etc/php.d/20-mysqlnd.ini,
/opt/plesk/php/8.2/etc/php.d/50-xdebug.ini,
/../

 

Using grep

php -i | grep php.ini

Response

Configuration File (php.ini) Path => /opt/plesk/php/8.2/etc
Loaded Configuration File => /var/www/vhosts/{domain}/etc/php.ini

 

 

Resolving the error

Now that you know the php.ini file being used (for me it was /etc), you can edit the php.ini file through using the vi command either going to the directory path and using:

vi php.ini

or 

vi /etc/php.ini

While in edit mode, perform a quick search rather than scrolling through the file using /{search term}.  In this instance search for upload_max_filesize, subsequently the find entry will be

/upload_max_filesize

The search command will take you to the following area:

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
;upload_tmp_dir =

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

Change the upload_max_filesize from 2M to your required size.

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

 

You will also need to check the post_max_size.  Use the same process as above to locate and change this setting.

/post_max_size

The search command will take you to the following area:

; Whether PHP will read the POST data.
; This option is enabled by default.
; Most likely, you won't want to disable this option globally. It causes $_POST
; and $_FILES to always be empty; the only way you will be able to read the
; POST data will be through the php://input stream wrapper. This can be useful
; to proxy requests or to process the POST data in a memory efficient fashion.
; http://php.net/enable-post-data-reading
;enable_post_data_reading = Off

; 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.
; http://php.net/post-max-size
post_max_size = 8M

; Automatically add files before PHP document.
; http://php.net/auto-prepend-file
auto_prepend_file =

Change the post max size to the same as the upload_max_filesize noted above

post_max_size = 10M

 

Save and close vim, press [Esc] key and type :wq!

[esc]:wq!

Done.

Once you have completed the above steps, restart your server for the changes to apply.  Go to yoursite.com/admin/reports/status/php to check if the changes were applied.

Related articles