Learn how to increase the PHP upload_max_filesize limit in Ubuntu with this easy step-by-step guide. This is necessary if you want to upload files larger than the default size.
How to Increase upload_max_filesize in PHP Ubuntu
What is upload_max_filesize?
The upload_max_filesize
directive in PHP sets the maximum size of a file that can be uploaded. When a script tries to upload a file that is larger than the upload_max_filesize
value, it will be terminated and the user will see a "File upload error: The uploaded file exceeds the upload_max_filesize directive in php.ini." message.
Why might you need to increase upload_max_filesize?
If you are running a PHP script that needs to upload large files, such as an image processing script or a file sharing site, you may need to increase the upload_max_filesize
value. Otherwise, you will see the "File upload error: The uploaded file exceeds the upload_max_filesize directive in php.ini." message.
How to increase upload_max_filesize in PHP Ubuntu
There are two ways to increase the upload_max_filesize
value in PHP Ubuntu:
upload_max_filesize
and change the value to the desired maximum file size. For example, to increase the upload_max_filesize
value to 256 MB, you would change the line to:upload_max_filesize = 256M
Once you have made the change, save and close the php.ini file.
2. Use the ini_set()
function. The ini_set()
function allows you to set PHP configuration values at runtime. To increase the upload_max_filesize
value using the ini_set()
function, add the following code to your PHP script:
ini_set('upload_max_filesize', '256M');
This will set the upload_max_filesize
value for the current script to 256 MB.
Which method should you use?
It is generally recommended to edit the php.ini file to increase the upload_max_filesize
value. This will set the upload_max_filesize
value for all PHP scripts on your server. However, if you only need to increase the upload_max_filesize
value for a specific script, you can use the ini_set()
function.
Restarting Apache
After you have increased the upload_max_filesize
value, you need to restart Apache for the changes to take effect. To do this, run the following command:
sudo systemctl restart apache2
Testing the changes
To test the changes, you can try uploading a file that is larger than the previous upload_max_filesize
value. If the file is uploaded successfully, then the changes have taken effect.
Troubleshooting
If you are still seeing the "File upload error: The uploaded file exceeds the upload_max_filesize directive in php.ini." message after increasing the upload_max_filesize
value, there are a few things you can try:
upload_max_filesize
value to a higher value.Conclusion
Increasing the upload_max_filesize
value in PHP Ubuntu is a relatively straightforward process. By following the steps above, you can increase the upload_max_filesize
value to prevent your PHP scripts from being terminated when trying to upload large files.