How to set and use PHP_INI_SCAN_DIR environment variable in PHP? [duplicate]

走远了吗. 提交于 2020-01-13 05:47:08

问题


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.



来源:https://stackoverflow.com/questions/49485364/how-to-set-and-use-php-ini-scan-dir-environment-variable-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!