What is php.ini
What is the php.ini file purpose?
In this post we are going to explain to you what is the php.ini file purpose and what do you use it for.
php.ini file is a configuration file which is used to configure different directives in the exectuion of the PHP script. This allows an easy administration of the Apache web servers as well as intalling different application manually or using Softaculous. In the php.ini file are located all applications’ module settings. For example settings like:
- Memory limit
- Time for execution of a script
- Global variables – some applications require an additional directives in the main php.ini file or an additional one in particular directory.
- Max uploading file size
- Log error
- Customized Errors and others.
Locations of the php.ini file.
- SAPI module specific location (PHPIniDir directive in Apache 2, -c command line option in CGI and CLI, php_iniparameter in NSAPI, PHP_INI_PATH environment variable in THTTPD)
- The PHPRC environment variable. Before PHP 5.2.0, this was checked after the registry key mentioned below.
- As of PHP 5.2.0, the location of the php.ini file can be set for different versions of PHP. The following registry keys are examined in order: [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z],[HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x], where x, y and z mean the PHP major, minor and release versions. If there is a value for IniFilePath in any of these keys, the first one found will be used as the location of the php.ini (Windows only).
- [HKEY_LOCAL_MACHINE\SOFTWARE\PHP], value of IniFilePath (Windows only).
- Current working directory (except CLI).
- The web server’s directory (for SAPI modules), or directory of PHP (otherwise in Windows).
- Windows directory (C:\windows or C:\winnt) (for Windows), or –with-config-file-path compile time option.
Or you can choose to create a script to show the location of the file:
You’ll need to create a very simple php script and place it in your home directory. Using a script editor or a plain text editor (not a word processor) create file called phpinfo.php with this code:
<?php phpinfo(); ?>
That’s all you need. Just one single line. Save the file and name it phpinfo.php.
Upload this file to the public_html directory or whatever your main HTML directory is called.
In your browser address bar, access the file by typing in: http://yourdomain.com/phpinfo.php
You’ll get a complete list of all your php settings. In the phpinfo.php page you can see:
- the PHP version at the top of the file.
- the location of your php.ini file
If you scroll down the page, and you can find the current version of MySQL. and php settings like safe_mode and register_globals and much much more.
Execution of the php.ini file.
During the execution of a PHP script, the web server first looks for a php.ini file in order to execute the particular configuration for the application. It’s like setting up the application with its parameters. For the server module versions of PHP, this happens only once when the web server is started. For the CGI and CLI versions, it happens on every invocation.
The php.ini file is mainly configured by the server administrator for optimal settings. Every webserver has one default php.ini file which is global for every user on the server. This global php.ini file is load on every script’s execution. If there are any changes in the php.ini file, the webvserver must be restarted so the changes will take effect. So, if a user requires specific configuration, the best way is to create a separate php.ini file. The separate php.ini file is only effective for the directory and subdirectories of its location.
The best way is to make a php.ini file backup copy before you make any changes to it.
Now you know how to use php.ini file. Simple isn’t it?
For other useful posts, please visit our Library.