2.7. PHP setup

PHP has a huge variety of settings that are concentrated in the file php.ini. Immediately after installation, instead of the php.ini file, you can find only two files:

  • php.ini-production – the recommended set of parameters for the production server;
  • php.ini-development – the recommended set of parameters for a developer’s workstation.

For local development, the php.ini-development file should be renamed to php.ini. By default, the PHP interpreter sequentially searches for the configuration file in the following places:

  • along the path specified in the PHPRC environment variable;
  • in the current directory (if the script is executed under the control of the Web server);
  • in the C:\Windows\directory in the case of Windows, in the /etc/ or /etc/php7/ directory in Linux, in the /usr/local/etc/php7.0 directory on Mac OS X or in the compilation directory for any other operating system .

If there are several php.ini files and you are not sure which of them is currently being used, you can find out the path to the used php.ini file from the report of the phpinfo() information function (Listing 2.2).

Listing 2.2. Information about PHP. phpinfo.php file:


The function displays detailed information about all the parameters of PHP. The path to the php.ini file, which is currently used by PHP, is specified in the Loaded Configuration File parameter.

You can explicitly tell the PHP location of the php.ini file with the -c option. For Windows, the command might look like this:

php -s -c C:\php\php.ini

For a UNIX-like operating system:

php -s -с /etc/php .ini

The PHP configuration file is a plain text file that can be opened using any editor. The content of the php.ini file consists of sections and directives. Sections are enclosed in square brackets, for example [PHP], followed by directives that have the following format:

directive = value

Here directive is the name of the directive, and value is its value. All lines with a semicolon (;) at the beginning are considered comments and are ignored.

It is allowed not to specify the value value. In this case, the directive is initialized with an empty string. The same result can be achieved by setting it to none.

Immediately after installing PHP, you should edit at least one directive – the current time zone. In order to set any time zone, you need to find the date.timezone directive and bring it to the form:

date.timezone = ‘Europe/Moscow’

If the embedded server is still running, you will need to restart it in order for the changes in php.ini to take effect.