By default, PHP allows you to upload a file of maximum size limit of 2MB. This can be quite restrictive if you are using WordPress which requires you to upload images frequently. In this article, we will look at how to increase or set file upload size limit in PHP. You can use them to change file upload size in PHP.
How to Change Max File Upload Size in PHP
Here are the steps to increase max file upload size in PHP.
1. Open PHP Configuration file
Open terminal and run the following command to open PHP configuration file on your system.
# vim /etc/php.ini [On Cent/RHEL/Fedora] # vim /etc/php/7.0/apache2/php.ini [On Debian/Ubuntu]
2. Change file upload size limit
By default, the max file upload size limit is 2MB. You need to modify the upload_max_filesize and post_max_size variables in PHP configuration to set file upload size limit. Here is an example to increase file upload size limit to 10MB. Please note, the file size is specified as 10M to mean 10MB.
upload_max_filesize = 10M post_max_size = 11M
post_max_size variable determines the maximum amount of data supported in a POST request. Keep its value slightly above that of upload_max_filesize. This is because when you upload a file, its POST request will be slightly bigger than the uploaded file’s size, due to request headers and other metadata. So when you upload a file of size 10MB its POST request will be more than 10MB. Therefore, you need to keep post_max_size a little bigger than upload_max_filesize to avoid errors.
Also read : How to Host Multiple Websites on NGINX
3. Restart Server
Once you have made the above changes, restart your Apache server to apply changes.
$ sudo service apache2 restart
That’s it. Now the file upload size limit will be increased automatically from the very next request.
In this article, we have described how to increase max file upload size limit in PHP. This is very useful if your website is running on WordPress and you need to upload files larger than 2MB.