How to Change PHP Max Upload Size

How to Change PHP Max Upload Size on a Debian Computer

When hosting applications or websites that rely on PHP, you may need to increase the maximum upload file size your server allows. This is particularly relevant for uploading large images, videos, or database files. This guide will walk you through the steps to check your PHP version and modify the upload size settings on a Debian system.

Step 1: Check Your PHP Version

The location of the PHP configuration file (php.ini) and its contents may vary depending on the PHP version installed on your system. Follow these steps to determine your PHP version:

  1. Open a terminal on your Debian machine.
  2. Run the following command:
   php -v

Example output:

   PHP 8.1.12 (cli) (built: Nov 14 2023 12:00:00) ( NTS )
   Copyright (c) The PHP Group
   Zend Engine v4.1.12, Copyright (c) Zend Technologies

This indicates you are using PHP version 8.1.

Alternatively, if you are running a web server, you can create a PHP file to display this information:

  1. Create a file named info.php in your web server’s root directory (e.g., /var/www/html/):
   sudo nano /var/www/html/info.php
  1. Add the following content:
   <?php
   phpinfo();
   ?>
  1. Open this file in your web browser by navigating to http://your-server-ip/info.php.
  2. Look for the PHP version displayed at the top of the page.

Step 2: Locate the PHP Configuration File

The php.ini file controls many PHP settings, including the maximum upload size. The exact location of this file depends on your PHP version and setup:

  • For PHP installed via packages, it is usually located in /etc/php/{version}/{cli|apache2|fpm}/php.ini. Replace {version} with your PHP version (e.g., 8.1) and choose the appropriate directory based on your setup:
  • cli for command-line interface
  • apache2 if you are using Apache
  • fpm if you are using PHP-FPM

Step 3: Update the Max Upload Size

  1. Open the appropriate php.ini file using a text editor. For example, if you are using Apache with PHP 8.1:
   sudo nano /etc/php/8.1/apache2/php.ini
  1. Search for the following settings in the file:
   upload_max_filesize = 2M
   post_max_size = 8M
  • upload_max_filesize controls the maximum size of individual files that can be uploaded.
  • post_max_size controls the total size of POST data, which includes file uploads.
  1. Update the values as needed. For example, to allow uploads up to 50MB:
   upload_max_filesize = 50M
   post_max_size = 50M
  1. Save and exit the editor (Ctrl+O, Enter, Ctrl+X in nano).

Step 4: Restart Your Web Server

After making changes to the php.ini file, restart your web server to apply them:

  • For Apache:
  sudo systemctl restart apache2
  • For PHP-FPM (e.g., if you are using Nginx):
  sudo systemctl restart php8.1-fpm

Step 5: Verify the Changes

To confirm the new settings:

  1. Reload the info.php file in your browser.
  2. Look for the updated values of upload_max_filesize and post_max_size.

Conclusion

Changing the PHP max upload size on a Debian system is straightforward, but it requires careful attention to the PHP version and the appropriate configuration file. By following these steps, you can ensure your server supports larger file uploads as needed for your applications. Remember to keep backups of configuration files before making changes to avoid accidental misconfigurations.

About Author

Related Posts

php8 gd

PHP8 gd Activate after installation

PHP8 GD activate after installation. GD doesn’t get activated by default. Not even a reboot after installation will activate it. So how do we do it? In…

Debian – Basic LAMP

Setup a basic LAMP, enables you to host cool web applications. LAMP is Linux, Apache, MySQL & PHP (guess Perl or Python should qualify as well). I…

Leave a Reply