Edit File Upload Size for PHP Applications

I’ve been asked this question a number of times for a variety of PHP-based applications including Moodle, WordPress and Omeka and so it’s worth documenting here.

The installation of PHP is what is controlling the maximum size of your file uploads.  By default, you are restricted to a maximum of 2 MB upload file size.  Here are the settings that control this configuration:

1. upload_max_filesize – This sets the maximum size of an uploaded file

2. post_max_size – This sets the maximum size of post data.  This setting is related to the upload setting in that it must be the same or larger than the value set in upload_max_filesize.

3.  memory_limit – This set the maximum amount of memory in bytes that a script is allowed to allocate.  Generally this setting should be larger than post_max_size.

Step-by-step – edit php.ini

Edit the php.ini file (note:  there may be more than one php.ini file on a server – typical locations are /etc/php.ini, /etc/php.d/cgi/php.ini or /usr/local/etc/php.ini):

 #  vi /etc/php.ini

Sample php.ini file:

 
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
; Maximum allowed size for uploaded files.
; http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize
upload_max_filesize = 20M

;;;;;;;;;;;;;;;;;
; Data Handling ;
;;;;;;;;;;;;;;;;;
; Maximum size of POST data that PHP will accept.
; http://www.php.net/manual/en/ini.core.php#ini.post-max-size
post_max_size = 25M

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
; Maximum amount of memory a script may consume (128MB)
; http://www.php.net/manual/en/ini.core.php#ini.memory-limit
memory_limit = 32M

Save the file and close it. Then restart the web server (showing an example of restart with Apache on RedHat ecosystem distro):

# service httpd restart
Facebooktwittermail
Tagged with: , , , , , , ,

Leave a Reply

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