How to set and use PHP_INI_SCAN_DIR environment va

2020-07-24 04:27发布

问题:

I've installed PHP 7.2.3 on my machine running on Windows 10. I've installed PHP and Apache httpd 4.29 using latest copy of XAMPP package.

I come across following text from the PHP Manual

It is possible to configure PHP to scan for .ini files in a directory after reading php.ini. This can be done at compile time by setting the --with-config-file-scan-dir option. In PHP 5.2.0 and later, the scan directory can then be overridden at run time by setting the PHP_INI_SCAN_DIR environment variable.

It is possible to scan multiple directories by separating them with the platform-specific path separator (; on Windows, NetWare and RISC OS; : on all other platforms; the value PHP is using is available as the PATH_SEPARATOR constant). If a blank directory is given in PHP_INI_SCAN_DIR, PHP will also scan the directory given at compile time via --with-config-file-scan-dir .

I tried below code but couldn't set the environment variable PHP_INI_SCAN_DIR

        <?php
            $_ENV['PHP_INI_SCAN_DIR'] = "Jumbo";
            print_r(getenv());
        ?>

Someone please make me understand what exactly is PHP_INI_SCAN_DIR and how to use it/set it?

回答1:

  • You can use Apaches SetEnv in a .htaccess file or <vhost> section.
    https://serverfault.com/questions/224685/php-ini-disable-scan-this-dir-for-additional-ini-files

    SetEnv PHP_INI_SCAN_DIR C:/web/app/conf.d/
    
  • On Windows you can also go to the control panel and set a global environment variable, or configure it per-service AFAIK.

  • Or install MSVC and recompile PHP to set custom ./configure options (such as --with-config-file-scan-dir).

    You probably do not want to do that.