IIS: .htaccess php_flag / php_value alternative?

2019-06-20 14:53发布

问题:

For IIS (5.0 or higher), are there alternatives to apache's .htaccess directives php_flag and php_value to set PHP_INI_PERDIR config values?

Thanks.

回答1:

Unfortunately, it seems that PHP_INI_PERDIR values cannot be modified (only PHP_INI_USER can). Here is the official information from php.net regarding changes of PHP configuration on Windows:

http://www.php.net/manual/en/configuration.changes.php#configuration.changes.windows



回答2:

Since PHP 5.3.0, you can use .user.ini files.

  1. Do a phpinfo(), and find these entries:

    • user_ini.filename, and
    • user_ini.cache_ttl.

  2. user_ini.filename is the name of the per-directory config file. Its value is usually .user.ini.

  3. Create the file .user.ini and put it in the directory you want to config.
  4. The format of .user.ini is just like php.ini. For example, it may contain something like this:

    ; Override value of upload_max_filesize
    upload_max_filesize = 4M
    
  5. Run phpinfo() again to check that the value has been overridden by your .user.ini.

Notes:

  1. For performance reasons, the .user.ini file is cached, so you may have to wait until the cache expires. The timeout is specified by user_ini.cache_ttl. For example, if user_ini.cache_ttl is 300, it means that the .user.ini file is cached for 300 seconds.
  2. The config file name is .user.ini, starting with a dot.
  3. This technique works for CGI/FastCGI SAPI only. See the doc for details.