change PHP configuration settings

In this article we will discuss about possible ways of changing PHP configuration settings.

Changing PHP Configuring settings are easy. Mainly there are 3 ways of changing PHP configurations settings. They are
1) Through php.ini file
2) Through .htaccess file
3) Through ini_set() function.

Through php.ini file :

The php.ini file is the main PHP configuration file, and most immediate way to affect PHP’s functionality. The php.ini file is read each time PHP script gets executed. This file consists of all the PHP configuration settings with detailed documentation/commented of each setting.

Please check this article for detailed information about php.ini file

Through .htaccess file :

The majority of ISPs provide Apache web server hosting on Linux or Unix platforms. Hopefully, they’ve also granted “AllowOverride Options” or “AllowOverride All” privileges in Apache’s httpd.conf configuration. This allows you to create an .htaccess file within your application’s root folder overrides the default Apache and PHP configuration.

In .htaccess  usage only two PHP directives are allowed

1) php_flag  ( Used to set on/off values)

Example : php_flag register_globals off

2) php_value  ( Used to set the values)

Example : php_value upload_max_filesize 20M

Don’t use php_value to set boolean values. use php_flag instead.

Please check this article  for detailed information about php.ini file

Through ini_set() function :

Some of the hosting server ( shared hosts ) do not allow the use of php.ini file for modifications of default PHP configuration. In order to modify the global PHP settings, we need to use the ini_set() PHP function.

ini_set PHP function requires two string arguments. First argument always represent setting name and the second argument is the value for the setting.

For example to change  the of Maximum Execution Time of a script through ini_set function, Use the below code.

ini_set(‘max_execution_time’, ‘600’); //600 seconds = 10 minutes

Always use ini_set function at the top of the script.

Settings that are through ini_set() function are applicable only to current script. There after it continues to use the settings from php.ini file.

Please check this article for detailed information about ini_set() function.

Usefull Information :

php_ini modes will plays a key role to suggest the best way of editing the global configuration setting .

There are 4 different types of php_ini_ modes and they are given below :

PHP_INI_USER        (Entry can be set in user scripts (like with ini_set()) or in the Windows registry. Since PHP 5.3, entry can be set in .user.ini)
PHP_INI_PERDIR    (Entry can be set in php.ini, .htaccess, httpd.conf or .user.ini (since PHP 5.3) )
PHP_INI_SYSTEM    (Entry can be set in php.ini or httpd.conf)
PHP_INI_ALL             (Entry can be set anywhere)

To find the php_ini mode of each setting click here


Leave a Reply

Your email address will not be published. Required fields are marked *