# Custom PHP settings for one folder (.htaccess and .user.ini)

> Give one folder or app different PHP settings, such as a higher memory limit or upload size, using .htaccess or a .user.ini file.

Source: https://helpcenter.ruachost.com/developers/php/custom-php-settings-per-directory-with-user-ini-files/

Most people should change PHP settings in cPanel's **Select PHP Version → Options**. Those settings apply to your whole account. See [Changing your PHP version and settings](https://helpcenter.ruachost.com/cpanel/software/changing-php-versions-and-settings-using-php-selector/).

Use the methods below only when **one folder or app** needs different settings from the rest of your account. They change settings only, not the PHP version. Your PHP version is always the one chosen in Select PHP Version.

## Method 1: .htaccess (recommended)

Ruachost servers run LiteSpeed, which reads PHP settings from `.htaccess` files.

1. In cPanel's **File Manager**, open the folder, for example `public_html/shop`. Click **Settings** and tick **Show Hidden Files** so you can see `.htaccess`.
2. Edit `.htaccess` (create it if it doesn't exist) and add the settings you need at the end:

```apache
php_value memory_limit 1024M
php_value upload_max_filesize 256M
php_value post_max_size 256M
php_value max_execution_time 300
php_value max_input_vars 20000
php_value date.timezone Africa/Lagos
php_flag display_errors Off
php_value output_buffering 4096
```

Some settings, such as `output_buffering`, aren't in Select PHP Version and can only be changed this way. Use `php_value` for numbers and text, and `php_flag` for settings that are `On` or `Off`. The settings apply to the folder and every folder inside it.

> **Caution:**
A mistake in `.htaccess` can cause a **500 Internal Server Error**. If that happens, remove the lines you added. Don't add `AddHandler` or `SetHandler` lines for PHP, because they override your PHP version.

## Method 2: .user.ini

You can also create a file called `.user.ini` in the folder, with settings written like this:

```ini
memory_limit = 1024M
upload_max_filesize = 256M
post_max_size = 256M
max_execution_time = 300
date.timezone = "Africa/Lagos"
```

PHP checks `.user.ini` files every few minutes, so changes may take up to 5 minutes to apply.

## Check that it worked

Create a file called `info.php` in the same folder containing `<?php phpinfo();`, open it in your browser, and look for the setting. The **Local Value** column shows the value for that folder. Delete `info.php` when you're done. See [Viewing PHP settings with phpinfo()](https://helpcenter.ruachost.com/developers/php/viewing-php-settings-with-the-phpinfo-function/).

## What you can't change

- **The PHP version per folder.** One PHP version applies to your whole account.
- **Limits above your plan's resources.** For example, a 2 GB `memory_limit` won't help if your plan has less RAM. See [PHP memory limit vs your plan's RAM](https://helpcenter.ruachost.com/developers/php/resolving-the-allowed-memory-size-exhausted-php-error-message/).
- **Some server-wide security settings**, which are locked for all accounts.

## Cron jobs and the command line

Settings in `.htaccess` don't apply to cron jobs or scripts run over SSH. See [Using a custom php.ini file for cron jobs](https://helpcenter.ruachost.com/developers/php/using-a-custom-php-ini-file-for-cpanel-cron-jobs/).
