Home > Help Center > General > What does the PHP.INI file is used for?

What does the PHP.INI file is used for?

Each hosting server is set to work with optimal values ​​to be able to successfully deliver the resources needed by sites of the hosting users.

It can even be said that the system administrators approach is often intentionally conservative in terms of resources and permissions to achieve a very high level of security and reliability of the hosting servers.

The default php.ini file

The same applies for the configuration settings of PHP scripting language.

The PHP's configuration file - php.ini is the latest and most immediate way to influence the PHP functionality. The php.ini file is read from the web server every time PHP is loaded (initialized).

PHP settings are not a secret and you can see them if you create a .php file with a random name (do not make it easier for hackers by naming the file phpinfo.php), containing only the PHP function phpinfo() and load the file into a browser:

php ini file

This function shows all PHP settings, and the parameters Configuration File (php.ini) Path and Loaded Configuration File show where the base php.ini file is located and whether its values ​​are currently loaded:

php ini file

You might wonder why two settings are needed to show the same thing?

Custom php.ini file

Because PHP allows the user to create their own php.ini file in the host directory and to overwrite the main PHP configuration parameters with a customized ones.

That is why in the beginning we mentioned, that usually the default server settings are sometimes lowered - because the users has the ability to customize the parameters according to the needs of their own sites.

Let's create a php.ini file in the public_html directory, to enter a different value for the parameter memor_limit and to refresh the browser (in the example confp.php), which contains the function phpinfo():

php ini file

The Loaded Configuration File parameter now specifies the path to the local php.ini file (which we created), showing that all changes in this file will overwrite the default values ​​in the main php.ini file.

memory_limit = 128M is the default value in the main php.ini file:

php ini file

memory_limit = 138M is the custom value in our local php.ini file:

php ini file

php.ini files have no recursive action by default

The PHP settings, specified in the php.ini file are not recursive by default - they do not change the settings in their subdirectories.

Let's check whether this is true.

We copy confp.php to the hostpulse-demo.net subdirectory, where the 'hostpulse-demo.net' domain is configured and we load the URL http://hostpulse-demo.net/confp.php:

php ini file

Although we have a correct php.ini file in public_html, its settings are not valid in the hostpulse-demo.net subdirectory and the PHP main settings are applied in that subdirectory.

If we want to have customized settings in the hostpulse-demo.net directory, we need to create a php.ini file in it. Let's create a php.ini file, containing this code: memory_limit = 148M and to refresh (with the F5 key) the URL http://hostpulse-demo.net/confp.php:

php ini file

Create a recursive php.ini file

If you want the personal settings of the local php.ini file in public_html to be valid for all sites in the hosting, you need to add the following code to the .htaccess file in public_html:

SetEnv PHPRC /home/cpaneluser/public_html/php.ini

Without changing anything from the previous example, we create the above entry and refresh the URL: http://hostpulse-demo.net/confp.php:

php ini file

Now the subdirectory loads the php.ini settings from public_html, although it has its own php.ini file, containing this value: memory_limit = 148M :

php ini file

Now we are facing an interesting problem: is it possible the php.ini file in public_html to have a recursive action in the hosting, but if we need a custom settings in separate directories, to use a different php.ini file?

Yes, we need to create an .htaccess file in the directory in question, in which file instead of the path to the recursive php.ini file, we must enter the path to the local php.ini file:

SetEnv PHPRC /home/cpaneluser/public_html/hostpulse-demo.net/php.ini

php ini file

php ini file

We will add additional explanations to the examples above because the management of PHP is important task and we do not want to leave even smallest place for any confusion:

  • The PHP settings from the main php.ini file on the server are used when there is no custom php.ini file in public_html directory and the default value memory_limit = 128M is loaded from the URL http://example.net/confp.php;
  • If we create a custom php.ini file in public_html directory with value memory_limit = 138M, when we refresh the browser the value from the local file (138M) will overwrite the value of the main php.ini file (128M);
  • To use custom PHP settings in a subdirectory, we must create a local php.ini file with value memory_limit = 148M and we also need to create an .htaccess file, containing the path to the local php.ini file in /public_html/hostpulse-demo.net; To load the custom PHP settings (148M) we need to enter in the browser's address bar the URL http://hostpulse-demo.net/confp.php;

The php.ini file syntax

There are some features when working with php.ini file, which we'll describe below:

  • the directives (parameters) are sensitive to the register (uppercase and lowercase), while the values ​​of the directives are not;
  • the directives and values ​​are divided by an equal sign (=);
  • blank spaces and lines are ignored;
  • any text after a semicolon (;) on the same line is ignored;
  • section markers - text in square brackets [php] are also ignored;
  • the strings are enclosed in double quotes - include_path = ".: /usr/local/lib/php";
  • boolean values ​​can be set as: true, on, yes; false, off, no, none;


`; this is a comment that is ignored. "

`memory_limit = 8M; this text is also ignored."

register_globals = off

Important: When entering directives in a custom php.ini file, we recommend that you always copy them from the browser ​​to avoid writing errors.

We hope the information in this article will help you more easily create and manage your custom PHP settings.

Still not finding what you're looking for?

Contact our support team with any additional questions or concerns.

Contact support