---
title: "Changing PHP settings"
date: "2014-10-29"
category: "php"
slug: "changing-php-settings"
---

Certain default PHP settings may need to be adjusted for your application. For example, you may need to accept larger file uploads or display errors during development. All settings except `open_basedir` and `memory_limit` can be adjusted.

## Using .htaccess

Create a [[htaccess-guide]] file named `.htaccess` within the [[where-is-site-content-served-from]] for a given domain. Rules apply recursively to all files in that directory, including nested subdomains.

> A `.htaccess` file in `/var/www` applies rules to all subdomains and domains within that directory -- useful for making global adjustments.

PHP directives use two forms:

### php_flag (Toggle Values)

Use `php_flag` to toggle a setting on or off:

**Example:** `php_flag display_errors On`

### php_value (Arbitrary Values)

Use `php_value` for non-boolean settings. Always surround values with quotes:

**Example:** `php_value upload_max_filesize "50M"`

## Per-Script Settings

Settings can be applied to individual PHP scripts using [ini\_set()](http://php.net/ini_set). This function takes a directive name and value, and must be placed after the opening `<?php` declaration.

_Example:_

<?php
 ini\_set('upload\_max\_filesize', '40M');
 ini\_set('error\_reporting', E\_ALL);
 ini\_set('display\_errors', false);
 // start the application
 include("loader.php");
 Loader::doStuff();
?>

In this example, `ini_set()` calls at the start of the script increase the file upload size, suppress browser error display, and log all errors.

## See Also

- PHP.net: [Description of core php.ini directives](http://php.net/manual/en/ini.core.php)
- [[viewing-php-settings]]
