How To Increase File Upload Size Limit In PHP 7
How To Increase File Upload Size Limit In PHP 7
June 06, 2020

This tutorial provides the steps to increase, decrease, or change the file upload size limit in PHP 7 for both Apache Web Server and NGINX Web Server. It provides the example code for Ubuntu 20.04 LTS and Windows 10. The steps should be the same on other versions of Windows, Ubuntu, and Linux systems.

Prerequisites

This tutorial assumes that you have access to an Ubuntu machine and Apache Web Server or NGINX Web Server, and PHP 7 are already installed on it. You may follow Install Ubuntu 20.04 LTS Desktop, Install Ubuntu 20.04 LTS On Windows Using VMware, and Spin Up Ubuntu 20.04 LTS Server On Amazon EC2 to install Ubuntu 20.04 LTS. You may also follow How To Install Apache 2 On Ubuntu 20.04 LTS and How To Install And Configure Nginx on Ubuntu 20.04 LTS.

Apache Web Server

We have to update the PHPs INI file to change the file upload size limit. Locate the php.ini file used by Apache Web Server according to your PHP installation and usage. I have provided a few examples as shown below.



# WampServer -> Example -> <WampServer Path>/bin/php/php7.4.14/php.ini

# XAMPP -> Example -> <XAMPP Path>/php/php.ini

# Ubuntu -> Apache Example -> /etc/php/7.4/apache2/php.ini

# Ubuntu -> NGINX Example -> /etc/php/7.4/fpm/php.ini

Now search your php.ini file for upload_max_filesize and post_max_size to update it as shown below.

# file upload size limit

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

# post request size limit

; 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
post_max_size = 16M

After updating the maximum file size and post request size, restart the Apache Web Server to apply the changes.

# Restart Apache Web Server - Ubuntu
sudo systemctl restart apache2

NGINX Web Server

Locate the php.ini file used by NGINX Web Server according to your PHP installation and usage. I have provided the default location as shown below.



# Ubuntu -> NGINX Example -> /etc/php/7.4/fpm/php.ini

Now search your php.ini file for upload_max_filesize and post_max_size to update it as shown below.

# file upload size limit

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

# post request size limit

; 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
post_max_size = 16M

After updating the maximum file size and post request size, restart the PHP FPM to apply the changes.

# Restart PHP FPM
sudo systemctl restart php7.4-fpm

Summary

This tutorial provided the required configurations to change or update the file upload size limit in PHP 7 for both Apache Web Server and NGINX Web Server.

Write a Comment

Click on the captcha image to get new code.
Discussion Forum by DISQUS