Certain default PHP settings may be insufficient for an application. For example, it may be necessary to accept large file uploads or display errors on-screen to facilitate rapid prototyping during early stages of an application.
PHP settings may be changed 3 ways, each with varying scope. All settings except for
memory_limit may be adjusted.
upload_max_filesize = 40M post_max_size = 60M short_open_tags = on
Create a .htaccess file called
.htaccess within the document root for a given domain. Rules will be applied recursively to all assets within that directory. If domains or subdomains are nested within that directory, then rules will apply to those additional domains as well.
A special-use case is creating a file called
/var/wwwthat will apply rules to all subdomains and domains located anywhere within
/var/www. This is a great, effective way to make global adjustments to all web content and likewise toggle off with minimum effort.
PHP directives come in 2 forms:
php_flag is to toggle a value on or off and takes 1 of 2 values:
php_flag display_errors On
This example will show errors in the browser as encountered.
php_value takes a non-toggleable value that can be anything. Always surround these values with quotes (“…”) to ensure the value is correctly parsed.
php_value upload_max_filesize "50M"This example will increase the maximum supported filesize to 50 MB for uploads.
Settings can be applied to a single PHP script within a folder via ini_set().
ini_set() takes 2 parameters, a directive and value and must be applied to the file ending in
.php. PHP commands always go after the opening declaration, <?php. It is similar as above, except unlike
php_flag above, On is simply
true and Off is
<?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(); ?>
At the start of a PHP script,
ini_set() commands are injected to increase file upload size, suppress displaying errors in the browser, and log all errors.