> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Increase the PHP Upload Size and Memory Limit

> Increase upload_max_filesize, post_max_size and memory_limit in the PHP-FPM php.ini, set client_max_body_size in Nginx, then restart PHP-FPM and reload Nginx.

To increase the PHP upload size, edit the PHP-FPM `php.ini` (on Ubuntu 24.04: `/etc/php/8.3/fpm/php.ini`) and set `upload_max_filesize = 64M`, `post_max_size = 72M` and `memory_limit = 256M`. Then allow the same size in Nginx with `client_max_body_size 64M;`. Restart PHP-FPM with `sudo systemctl restart php8.3-fpm` and reload Nginx. PHP's defaults are 2 MB uploads and 8 MB posts; Nginx's is 1 MB.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 5 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux / Rocky 9 / 10 | sudo, Nginx or Apache with PHP |

## Before you start

* Use a user with `sudo`. If you are `root`, leave out `sudo`.
* An upload passes three limits. The smallest one wins:
  1. **The web server**: Nginx `client_max_body_size` (default 1 MB), Apache `LimitRequestBody` (default 1 GiB).
  2. **PHP**: `upload_max_filesize` (default 2 MB) and `post_max_size` (default 8 MB).
  3. **Your app**, such as a WordPress plugin or a form library.

## Which php.ini do I edit?

PHP for the web and PHP on the command line read different files. `php --ini` shows only the command-line file, so use this table:

| Setup | File |
| - | - |
| Nginx or Apache with PHP-FPM, Ubuntu / Debian | `/etc/php/8.3/fpm/php.ini` (use your version, for example `8.4` on Debian 13) |
| Apache with `mod_php`, Ubuntu / Debian | `/etc/php/8.3/apache2/php.ini` |
| AlmaLinux / Rocky (PHP-FPM) | `/etc/php.ini` |
| Command line (Composer, cron) | Shown by `php --ini` |

## How to raise the PHP limits

**1. Edit php.ini**

```bash theme={null}
sudo nano /etc/php/8.3/fpm/php.ini
```

Find and change these lines (press `Ctrl+W` in nano to search):

```ini theme={null}
upload_max_filesize = 64M
post_max_size = 72M
memory_limit = 256M
max_execution_time = 120
```

`post_max_size` must be larger than `upload_max_filesize`, because a form post carries the file plus other fields. `memory_limit` should be larger than `post_max_size`.

**2. Restart PHP**

> [tab] Ubuntu / Debian (PHP-FPM)
>
> ```bash theme={null}
> sudo systemctl restart php8.3-fpm
> ```

> [tab] Apache mod\_php
>
> ```bash theme={null}
> sudo systemctl restart apache2
> ```

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo systemctl restart php-fpm
> ```

## How to raise the web server limit

> [tab] Nginx
>
> Add `client_max_body_size` inside the site's `server { }` block (or in `http { }` in `/etc/nginx/nginx.conf` for all sites):
>
> ```nginx theme={null}
> server {
>     server_name example.com;
>     client_max_body_size 64M;
>     # ...
> }
> ```
>
> ```bash theme={null}
> sudo nginx -t && sudo systemctl reload nginx
> ```

> [tab] Apache
>
> Apache's default `LimitRequestBody` is 1 GiB (1073741824 bytes), so you only need to change it for larger uploads or if a config lowered it. Set it in the `<VirtualHost>` or `<Directory>` block, in bytes:
>
> ```apache theme={null}
> LimitRequestBody 2147483648
> ```
>
> Then `sudo apache2ctl configtest && sudo systemctl reload apache2` (`apachectl` and `httpd` on AlmaLinux / Rocky).

## How to set limits for one site only

> [tab] .user.ini (PHP-FPM)
>
> Create `.user.ini` in the site's web root:
>
> ```ini theme={null}
> upload_max_filesize = 64M
> post_max_size = 72M
> memory_limit = 256M
> ```
>
> PHP-FPM reads it without a restart, but caches it for up to 5 minutes (`user_ini.cache_ttl = 300`).

> [tab] PHP-FPM pool
>
> In the site's pool file, for example `/etc/php/8.3/fpm/pool.d/www.conf`, add:
>
> ```ini theme={null}
> php_admin_value[upload_max_filesize] = 64M
> php_admin_value[post_max_size] = 72M
> php_admin_value[memory_limit] = 256M
> ```
>
> Then restart PHP-FPM. `php_admin_value` cannot be overridden by the app.

> [tab] .htaccess (Apache mod\_php)
>
> ```apache theme={null}
> php_value upload_max_filesize 64M
> php_value post_max_size 72M
> php_value memory_limit 256M
> ```
>
> This only works with `mod_php` and `AllowOverride All`. With PHP-FPM it causes a 500 error; use `.user.ini` instead.

`upload_max_filesize` and `post_max_size` cannot be changed with `ini_set()` inside PHP code. Use one of the methods above.

## How to check it worked

Create a temporary check file in the web root:

```bash theme={null}
echo '<?php foreach (["upload_max_filesize","post_max_size","memory_limit"] as $k) echo "$k = ".ini_get($k)."\n";' | sudo tee /var/www/example.com/limits.php
curl -H "Host: example.com" http://127.0.0.1/limits.php
sudo rm /var/www/example.com/limits.php
```

Expected output:

```text theme={null}
upload_max_filesize = 64M
post_max_size = 72M
memory_limit = 256M
```

In WordPress, **Media > Add New** shows the new "Maximum upload file size".

## Frequently asked questions

### I get "413 Request Entity Too Large". Which limit is it?

That comes from Nginx: raise `client_max_body_size`. The Nginx error log shows `client intended to send too large body: … bytes`.

### WordPress says "The uploaded file exceeds the upload\_max\_filesize directive in php.ini". I changed it. Why?

You edited the command-line `php.ini` or did not restart PHP-FPM. Edit the `fpm/php.ini` for the PHP version your site uses and restart that version's service. With several versions installed, see [multiple PHP versions](https://help.freakhosting.com/portals/other/how-to-install-multiple-php-versions.md).

### What memory\_limit should I use?

128M is PHP's default and fine for most sites; 256M suits WordPress with page builders or WooCommerce. Every PHP worker can use up to this amount, so very high values on a small VPS can cause [out-of-memory kills](https://help.freakhosting.com/portals/other/how-to-fix-out-of-memory-killed-processes.md).

### Large uploads time out. What else should I raise?

Raise `max_execution_time` in PHP and, for slow PHP responses behind Nginx, `fastcgi_read_timeout` (default 60 seconds) in the `location ~ \.php$` block.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every server guide in one place.

> [card] [Install WordPress](https://help.freakhosting.com/portals/other/how-to-install-wordpress-on-a-vps.md)
>
> Where upload limits matter most.

> [card] [Install a LEMP stack](https://help.freakhosting.com/portals/other/how-to-install-a-lemp-stack.md)
>
> Nginx with PHP-FPM.

> [card] [Multiple PHP versions](https://help.freakhosting.com/portals/other/how-to-install-multiple-php-versions.md)
>
> One php.ini per version.

> [card] [Check memory usage](https://help.freakhosting.com/portals/other/how-to-check-memory-usage-on-linux.md)
>
> Size memory\_limit safely.

***

> [!NOTE]
>
> **Checked against the official [PHP core ini directives](https://www.php.net/manual/en/ini.core.php), [PHP .user.ini documentation](https://www.php.net/manual/en/configuration.file.per-user.php), [nginx core module](https://nginx.org/en/docs/http/ngx_http_core_module.html) and [Apache core directives](https://httpd.apache.org/docs/2.4/mod/core.html#limitrequestbody)** on 4 November 2026; php.ini, `.user.ini` and pool overrides, the `limits.php` check and the Nginx 413 error tested on Ubuntu 24.04 LTS (Nginx 1.24.0, PHP-FPM 8.3.6). Commands can differ on other distributions or releases.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.