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

  1. 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:
    Ubuntu: /etc/php/<php_version>/apache2/php.ini, for example /etc/php/8.1/apache2/php.ini
    Centos: /etc/php.ini

  2. Open the php.ini file in a text editor.
    #  vi /etc/php/8.1/apache2/php.ini

  3. 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.

  4. 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.

  5. Save the php.ini file.
  6. 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.


Leave a reply

Your email address will not be published. Required fields are marked *


©2024 ZMATECH: Innovative solutions for your IT challenges.


We're not around right now. But you can send us an email and we'll get back to you, asap.


Log in with your credentials

Forgot your details?