# How to override PHP settings

You can override most runtime `php.ini` values - such as `memory_limit`, `max_execution_time` and
the upload size limits - per application, without root access. To choose the PHP **version** or tune
PHP-FPM, see [Configure PHP](configure.md) instead.

## Override per application with a `.user.ini` file

Create a `.user.ini` file in your application's document root (for example `public_html`) and add one
setting per line:

```ini
memory_limit = 512M
max_execution_time = 300
post_max_size = 600M
upload_max_filesize = 512M
```

Most settings that PHP allows to be changed at the directory level can be overridden this way.

> [!NOTE]
> PHP re-reads `.user.ini` only periodically - by default about every **5 minutes** - so a change is
> not always instant. Allow a few minutes before you test the result.

## Override for the command line

A `.user.ini` file applies to web requests only. For a one-off command-line run, pass the value with
`-d`:

```bash
php -d memory_limit=512M your-script.php
```

## Application-specific exceptions

Some applications set their own PHP values that take precedence over `.user.ini` for web requests.
Magento, for example, enforces limits through a `PHP_VALUE` line in its generated `50main.conf`
(see [Custom Nginx configuration](../nginx/configure.md)):

```nginx
fastcgi_param PHP_VALUE "memory_limit=2048M \n max_execution_time=18000";
```

If a `.user.ini` change has no effect on such a site, look for an override like this first.

## Verify

Confirm the value actually applied with a temporary `phpinfo()` page:

```php
<?php phpinfo();
```

Open it in your browser, search for the setting, then **delete the file** - never leave a
`phpinfo()` page on a live site.

## Related

- [Configure PHP](configure.md)
- [Switch PHP version](switch-php-version.md)
- [Fixing 413 errors](../../troubleshooting/http-4xx-errors.md)
- [Custom Nginx configuration](../nginx/configure.md)
