Increase File Upload and Post Size in PHP on a Linux Server
To increase the maximum file upload size or post size in PHP, you need to edit the php.ini configuration file. Here are the simple steps to follow:
NOTE: These steps were tested on Ubuntu 22.04
- Locate your php.ini file. The location of this file can vary depending on your operating system and PHP installation. You can find the location of the php.ini file by running php –ini in a terminal or command prompt.
# php --ini
# php -i | grep php.ini
NOTE: In most Linux systems, including Ubuntu, there are typically two PHP configuration files - one for the system and one for Apache web server. If you are running the above command in Ubuntu server, you may be preneted with a path to the system PHP, which might not create the expected impact impact. The correct path for the Apache php.ini file is as below:
/etc/php/<php_version>/apache2/php.ini, for example /etc/php/8.1/apache2/php.ini
- Open the php.ini file in a text editor.
# vi /etc/php/8.1/apache2/php.ini
- Find the following lines in the file:
upload_max_filesize = 2M
post_max_size = 8M
These lines control the maximum file upload size and post size, respectively. The values are set to 2 megabytes and 8 megabytes, respectively, in the example above.
- Increase the values to your desired limits. For example, to allow uploads of files up to 10 megabytes in size and post data up to 16 megabytes, you can change the lines to:
upload_max_filesize = 10M
post_max_size = 16M
Note that the values should be in megabytes and you should include the "M" at the end of the number.
- Save the php.ini file.
- Restart your web server service to apply the changes. In ubuntu, you would run the below command:
# systemctl restart apache2
After making these changes, your PHP application should be able to handle larger file uploads and post data.