How to increase upload file size for PHP application
The upload_max_filesize directive defines the maximum allowed size for file uploads in PHP. As file uploads are done using HTTP POST method, it is also limited by the post_max_size value. It means the actual maximum upload file size for PHP is bound to the lowest value of both post_max_size and upload_max_filesize.
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.
Maximum allowed size for uploaded files.
You can increase your PHP application's maximum upload file size by updating both upload_max_filesize and post_max_size directives in your PHP configuration file. You can also configure the same options in the .htaccess file if you don't have administrative access to the system.
Steps to increase upload file size for PHP application:
Open php.ini file using your preferred text editor.
$ sudo vi /etc/php/7.4/apache2/php.ini
Related: PHP configuration files
Search for upload_max_filesize directive.
; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 2M
Set your preferred value for upload_max_filesize.
upload_max_filesize = 128M
Search for post_max_size directive.
; 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
Set your preferred value for post_max_size.
post_max_size = 128M
This value should be set at least as high as upload_max_filesize value. Set the value to 0 to impose no limit on the size.
Restart your web server for the changes to take effect
Related: How to manage Apache service
Alternatively, you can add the following lines in your .htaccess and the setting will apply to scripts from within the .htaccess directory without having to mess with PHP's configuration.
php_value upload_max_filesize 128M php_value post_max_size 128M