At the time of PHP installation, php.ini is a special file provided as a default configuration file. It’s very essential configuration file which controls, what a user can or cannot do with the website. Each time PHP is initialized, the php.ini file is read by the system. Sometimes you need to change the behavior of PHP at runtime, then this configuration file is to use.
All the settings related to register global variables, upload maximum size, display log errors, resource limits, the maximum time to execute a PHP script and others are written in a file as a set of directives which helps in declaring changes.
Note: Whenever some changes are performed in the file, you need to restart our web server.
It helps in easy administration of web server using these configuration files. We can also write our own custom configuration files.
To check file path use the following program:
Note: Keys in the file are case-sensitive, keyword values are not spaces and lines starting with a semicolon are ignored. The file is well commented. The Boolean values are represented by On/Off, 1/0, True/False, Yes/No.
The file contains a set of directives with a set of respective values assigned to it. The values can be string, a number, a PHP constant, INI constants, or an expression, a quoted string or a reference to a previously set variable. Expression in the INI file is limited to bitwise operators or parentheses. Settings with a particular hostname will work under that particular host only.
Environment variables of php.ini file:
- memory_limit: This setting is done to show the maximum amount of memory a script consumes.
Important settings or common parameters of the php.ini file:
- enable_safe_mode = on Its default setting to ON whenever PHP is compiled. Safe mode is most relevant to CGI use.
- register_globals = on its default setting to ON which tells that the contents of EGPCS (Environment, GET, POST, Cookie, Server) variables are registered as global variables. But due to a security risk, the user has to ensure if it set to OFF for all scripts.
- upload_max_filesize This setting is for the maximum allowed size for uploaded files in the scripts.
- upload_tmp_dir = [DIR] Don’t uncomment this setting.
- post_max_size This setting is for the maximum allowed size of POST data that PHP will accept.
- display_errors = off This setting will not allow showing errors while running PHP project in the specified host.
- error_reporting = E_ALL & ~E_NOTICE: This setting has default values as E_ALL and ~E_NOTICE which shows all errors except notices.
- error_prepend_string = [“”] This setting allow you to make different color of messages.
- max_execution_time = 30 Maximum execution time is set to seconds for any script to limit the time in production servers.
- short_open_tags = Off To use XML functions, we have to set this option as off.
- session.save-handler = files You don’t need to change anything in this setting.
- variables_order = EGPCS This setting is done to set the order of variables as Environment, GET, POST, COOKIE, SERVER. The developer can change the order as per the need also.
- warn_plus_overloading = Off This setting issues a warning if + used with strings in a form of value.
- gpc_order = GPC This setting has been GPC Deprecated.
- magic_quotes_gpc = on This setting is done in case of many forms are used which submits to themselves or others and display form values.
- magic_quotes_runtime = Off If magic_quotes_sybase is set to On, this must be Off, this setting escape quotes.
- magic_quotes_sybase = Off If this setting is set to off it should be off, this setting escape quotes.
- auto-prepend-file = [filepath] This setting is done when we need to automatically include() it at the beginning of every PHP file.
- auto-append-file = [filepath] This setting is done when we need to automatically include() it at the end of every PHP file.
- include_path = [DIR] This setting is done when we need to require files from the specified directories. Multiple directories are set using colons.
- ignore_user_abort = [On/Off] This settings control what will happen when the user click any stop button. The default value is on this setting doesn’t work on CGI mode it works on only module mode.
- doc_root = [DIR] This setting is done if we want to apply PHP to a portion of our website.
- file_uploads = [on/off] This flag is set to ON if file uploads are included in the PHP code.
- mysql.default_host = hostname This setting is done to connect to MySQL default server if no other server host is mentioned.
- mysql.default_user = username This setting is done to connect MySQL default username, if no other name is mentioned.
- mysql.default_password = password This setting is done to connect MySQL default password if no other password is mentioned.
Configuration of php.ini file: Whenever we install PHP, we can locate the configuration file inside the PHP folder. If using xampp, we can find the configuration file in one or many versions, inside the path ‘\xampp\php’.
Note: Other versions of this file are php.ini-development and php.ini-production. The most preffered one is php.ini-development file.
- PHP | Get PHP configuration information using phpinfo()
- Laravel | Installation and Configuration
- How to store deployment configuration files in Node.js ?
- Slim Framework | Installation and Configuration
- Installation and Configuration Symfony Framework
- CakePHP Framework | Installation and Configuration
- Spring MVC using Java based configuration
- How to get file input by selected file name without path using jQuery ?
- How to reset selected file with input tag file type in Angular 9?
- How to import config.php file in a PHP script ?
- PHP | Basics of File Handling
- How to get file name from a path in PHP?
- PHP | Uploading File
- PHP | $_FILES Array (HTTP File Upload variables)
- PHP | fopen( ) (Function open file or URL)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.