php.ini File

by Vincy. Last modified on July 2nd, 2022.

While installing PHP, this file is provided with PHP installation settings. For that, it includes a set of directives provided with respective values. These directives are of two types based on the values they have. These are,

  1. Value Directive – It contains values with respect to the name of the directive. For example, include_path is a value directive that holds the default path to be included, if no URL is specified for the PHP include() function.
  2. Flag directive – It is considered as flags that can be set or unset by using boolean terms, like, on/off, 1/0, true/false and etc. For example, REGISTER_GLOBALS is set to off by default, since register_globals are deprecated in PHP.

This file has two sections based on which the value and flag directives can be set with. These sections are,

    1. HOST – The directives can be set for the hostname specified using this section. (i.e.) settings under a particular hostname will work only with that host. For example,
      [HOST="www.somedomain.com"]
      display_errors = off
      

      This setting will not allow displaying errors while running our PHP project on this host.

    2. PATH – Here configurations are set with a particular path specified. For example,
      [PATH="/home/user/.."]
      display_errors = on
      

Configuring php.ini

This file is located inside the PHP folder of the location where we have installed PHP. If we use the XAMPP package, we could find this file in \xampp\php.

After installing PHP, we can find one or more versions of a php.ini file. We need to choose any one of the preferable versions that should be renamed php.ini.

For example, if those versions are named php.ini_dist and php.ini_recommended, then we need to select the latter one. Because, it is an optimized file with respect to performance, security and etc. So, we need to rename php_ini_recommended as php.ini

If we use the XAMPP package to install PHP on our local machine, then there will be another set of two versions of this file, that is, php.ini-development and php.ini-production. Among them, php.ini-development is preferable to the other to rename as php.ini.

Change of Impact

We can make changes to this file on-demand basis. For example, if we want to access the remote file, we need to set the option allow_url_fopen to be enabled.

After making any change with either php.ini, we need to restart our XAMPP server (or any package using which the PHP is installed) to make these changes to be effective in our PHP environment.

php.ini Settings

This file includes settings related to the PHP environment features like error handling, remote access, file uploads, configuring image-related settings, for example setting the maximum size of images to upload and etc.

This file also has directives to configure with session and cookie-related settings. But, some of the php.ini directives are deprecated as of later versions of PHP.

We can also customize php.ini file as our own by following the default template of this file provided while installing PHP. By customizing our own PHP.ini file we can configure our PHP environment on a need basis.

Comments to “php.ini File”

Leave a Reply to Aditya Cancel reply

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

↑ Back to Top

Share this page