Welcome to PHPBash | Helping You to Become an Expert in PHP Programming. In this PHP Tutorial for beginners and professionals, I will cover details about The Dummies Guide to Php.ini Configuration File of PHP. The configuration file (php.ini) of PHP is read when PHP starts up. In case of web 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 Dummies Guide to Php.ini Configuration File of PHP Tutorial
This PHP tutorial covers all the topics of php.ini File Configuration of PHP like
1. What is php.in file?
2. What are PHP Directives and their types?
3. Important settings or common parameters of the php.ini file
Let's start PHP tutorial with questions, What is php.in file?
What is php.in file?
At the time of PHP installation, php.ini is a special file provided as a default configuration file. PHP's configuration file php.in is important file which is responsible for controlling what user can do and can't do with website. The configuration file (php.ini) of PHP is read when PHP starts up.
PHP comes packaged with two "ini" files. One that is recommended to be used in production environments and one that is recommended to be used in development environments. For example, if those versions are named as php.ini_dist and php.ini_recommended. If you are using XAMPP then the two versions of php.in will be php.ini-development and php.ini-production.
In case of web 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. php.ini file consist set of directives with their values. These directives of configuration file tells web server about behaviour of PHP.
|
PHP php.ini Configuration File |
In case you need to change the behaviour of PHP, then php.in configuration file can be accessed and modified.
IMPORTANT: If you modify php.in file, then you must Restart your Web Server for taking effect.
LOCATION: php.ini file can be found inside the PHP Directory. In case you are using XAMPP, the php.ini configuration file can be found in "xampp/php".
What are PHP Directives and their types?
Basically, Directives are variables used to configure PHP or PHP extensions. As described, These directives of configuration file tells web server about behaviour of PHP. Directive names are *case sensitive*. For Example, foo=bar is different from FOO=bar.
Directives are specified using the following syntax:
directive = value
The value can be a string, a number, a PHP constant (e.g. E_ALL or M_PI), one of the INI constants (On, Off, True, False, Yes, No and None) or an expression (e.g. E_ALL & ~E_NOTICE), a quoted string ("bar"), or a reference to a previously set variable or directive (e.g. ${foo})
The php.ini file Consist two types of directives. They are
1. Boolean/Flag directive – These directives are treated like flags that can be set or unset by using boolean values, like, on or off, 1 or 0, true or false. Boolean flags can be turned on using the values 1, On, True or Yes.They can be turned off using the values 0, Off, False or No.
2. Value Directive – It contains values with respect to the name of the directive.
Important settings or common parameters of the php.ini file
The following directives describe various php.in Configuration settings and their values.
1. display_errors = off
This setting will not allow showing errors while running PHP project in the specified host.
2. error_reporting = E_ALL & ~E_NOTICE:
This setting has default values as E_ALL and ~E_NOTICE which shows all errors except notices.
3. max_execution_time = 30
Maximum execution time is set to seconds for any script to limit the time in production servers.
4. short_open_tags = Off
To use XML functions, we have to set this option as off.
5. 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.
6. auto-prepend-file = [filepath]
This setting is done when we need to automatically include() it at the beginning of every PHP file.
7. auto-append-file = [filepath]
This setting is done when we need to automatically include() it at the end of every PHP file.
8. include_path = [DIR]
This setting is done when we need to require files from the specified directories. Multiple directories are set using colons.
9. 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.
10. file_uploads = [on/off]
This flag is set to ON if file uploads are included in the PHP code.
11. mysql.default_host = hostname
This setting is done to connect to MySQL default server if no other server host is mentioned.
12. mysql.default_user = username
This setting is done to connect MySQL default username, if no other name is mentioned.
13. mysql.default_password = password
This setting is done to connect MySQL default password if no other password is mentioned.
14.upload_max_filesize=value
This setting is for the maximum allowed size for uploaded files in the scripts.
15. upload_tmp_dir = [DIR]
Don’t uncomment this setting.
16. post_max_size =value
This setting is for the maximum allowed size of POST data that PHP will accept.
17. register_argc_argv = Off
This directive determines whether PHP registers $argv & $argc each time it runs. $argv contains an array of all the arguments passed to PHP when a script is invoked. $argc contains an integer representing the number of arguments that were passed when the script was invoked.
18. 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.
19. display_startup_errors = Off
The display of errors which occur during PHP's startup sequence are handled separately from display_errors.
20. log_errors = On
Besides displaying errors, PHP can also log errors to locations such as a server-specific log, STDERR, or a location specified by the error_log directive.
21. log_errors_max_len = 1024
Set maximum length of log_errors. In error_log information about the source is added. The default is 1024 and 0 allows to not apply any maximum length at all.
22. ignore_repeated_errors = Off
Do not log repeated messages. Repeated errors must occur in same file on same line unless ignore_repeated_source is set true.
23. html_errors = On
When PHP displays or logs an error, it has the capability of formatting the error message as HTML for easier reading. This directive controls whether the error message is formatted as HTML or not.
24. default_mimetype = "text/html"
PHP's built-in default media type is set to text/html.
25. default_charset = "UTF-8"
PHP's default character set is set to UTF-8.
26. file_uploads = On
Whether to allow HTTP file uploads.
27. allow_url_fopen = On
Whether to allow the treatment of URLs (like http:// or ftp://) as files.
28. allow_url_include = Off
Whether to allow include/require to open URLs (like http:// or ftp://) as files.
29. date.timezone
Defines the default timezone used by the date functions
30. session.use_cookies = 1
Whether to use cookies OR not.
31. session.name = PHPSESSID
Name of the session (used as cookie name).
32. session.cookie_lifetime = 0
Lifetime in seconds of cookie or, if 0, until browser is restarted.
33. session.cache_expire = 180
Document expires after n minutes.
34. engine = On
Enable the PHP scripting language engine under Apache.
35. short_open_tag = Off
This directive determines whether or not PHP will recognize code between <? and ?> tags as PHP source which should be processed as such. It is generally recommended that <?php and ?> should be used and that this feature should be disabled, as enabling it may result in issues when generating XML documents.
36. precision = 14
The number of significant digits displayed in floating point numbers.
37. max_input_vars = 1000
How many GET/POST/COOKIE input variables may be accepted.
38. memory_limit = 128M
Maximum amount of memory a script may consume (128MB)
These are some important directives available in php.ini configuration file. As mention earlier, if modify any directive value, do not forgot to restart your server in order to take effect.
I hope this PHP tutorial might have given a much better idea about "The Dummies Guide to Php.ini Configuration File of PHP". If you have any doubt/query related to PHP or Web Technologies, Please let me know in Comment Section. Please share it with your friends.
Sharing is caring ❤️
Thank you for Visiting PHPBash | Helping You to Become an Expert in PHP Programming. Keep Visiting for more Interesting concepts of Php language and web technologies from basics to advanced.
As well we will also share some ready-to-use, useful code snippets for beginners to kick start their web development project.
Want to Develop Website / Web Application or any Academic Project?
Do you want to build a modern, lightweight, responsive website and launch quickly?
I help to create the best websites / web applications and will be available for freelance work. contact: phpgems28@gmail.com
Comments
Post a Comment
Thank you so much.