|
This lesson cannot cover every configuration directive in php.ini in detailthere are simply too many. However, in the following sections you will learn how some of the most commonly used settings work. For a full reference, refer to www.php.net/manual/en/ini.php. Configuring the PHP EnvironmentThe following sections list some of the common configuration directives that affect the environment in which PHP runs. Each directive listed in the following sections is shown with its default entry from the php.ini file that is distributed with PHP 5, where the default is set. PHP Tag StylesThese directives allow you to select which tag styles can be used in a PHP script:
System Resource LimitsThe following directives allow you to manage the system resources available to a PHP script:
Form ProcessingYou can use these directives to change the way PHP interacts with web forms:
Include FilesYou can use the include_path directive to give a list of locations in which to search for a file referenced in an include or require statement. The locations are separated by colons on Linux/Unix systems and by semicolons on Windows systems. Often you need to ensure that include files are kept in a directory that is not directly accessible by a web server. The following example defines an include path that contains a directory parallel to the web root of /home/chris/public_html: php_value include_path .:/home/chris/include The period character (.) is used to indicate the current working directory, and in this example, it is given higher priority than the defined include directory. In this case, if an include statement finds a matching file in both locations, the one in the working directory will be used. This type of configuration allows you to use shared library files across your server but override them for some scripts when necessary. The auto_prepend_file and auto_append_file directives allow you to specify files that are automatically added at the start and end of each PHP script. The filename given is found in include_path, or a full path to the file can be given. A common use for auto_prepend_file is to automatically include part of the HTML layout before the output from your script so that all your pages look the same. Because auto_prepend_file is a PHP feature, only files parsed by PHP have the file prepended; static HTML pages do not.
Error LoggingAs you learned in Lesson 22, "Error Handling," PHP allows you to configure the strictness of error reporting and the means by which it is reported. The value of the error_reporting directive is a bitmask comprised of the values found in Table 22.1 in Lesson 22. You can use logical operators to combine values as follows: error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT The display_errors and log_errors directives determine whether an error is written to the screen display and web server log file, respectively. The default settings are as follows, with errors displayed to screen and not written to a file: display_errors = On log_errors = Off You can use the error_log directive to specify an alternate filename, as in the following example: error_log = /tmp/php_log Configuring PHP ExtensionsSome PHP extensions have their own directives that can be configured in php.ini to adjust the behavior of that extension. For clarity in the configuration file, section headings are used to separate extension-specific settings. For instance, all the settings that affect the MySQL extension are found in a section of php.ini that begins [MySQL]. Each directive name also has a prefix that indicates the extension to which it belongs (for example, mysql.connect_timeout or session.cookie_path). You can find documentation for extension-specific configuration directives in the online manual pages for each extension. Configuring System SecuritySome of the directives in php.ini that are not covered in this lessonmost notably the safe_mode directive and its related settingsconcern server security. These configuration options allow you to restrict certain types of functionality on the web server, and you will learn about them in Lesson 24, "PHP Security." |
|