To change the maximum upload file size for PHP, you need to modify two PHP configuration settings:
post_max_size. Here are the steps you can follow:
Step 1:- Locate the PHP configuration file called
php.ini. If you are not sure where this file is located, you can create a new PHP file with the following code:
<?php phpinfo(); ?>
Then, open the file in a web browser, and look for the “Loaded Configuration File” value. This will tell you where the
php.ini file is located.
Here is a screenshot showing the same.
Step 2:- Open the
php.ini file in a text editor.(e.g nano php.ini). You will need administrative privilege to edit it(e.g sudo user)
Step 3:- Search for the
upload_max_filesize setting. This sets the maximum size of an individual file that can be uploaded. By default, this is usually set to 2M (2 megabytes).
Step 4:- Change the value to the desired maximum file size. For example, to set the maximum file size to 20 megabytes, you can use the following:
upload_max_filesize = 20M
Note that you can use different size units, such as
K for kilobytes or
G for gigabytes.
Step 5:- Search for the
post_max_size setting. This sets the maximum size of the entire HTTP POST request, which includes the uploaded files. By default, this is usually set to 8M.
Step 6:- Change the value to the desired maximum request size. For example, to set the maximum request size to 25 megabytes, you can use the following:
post_max_size = 25M
Step 7:- Save the
php.ini file and restart your web server. This will apply the changes.
Congratulations!, your PHP scripts will be able to handle larger file uploads now.