'Overwrite' php.ini settings

前端 未结 5 950
忘了有多久
忘了有多久 2020-12-21 08:30

I have a folder, and for all php files in that folder (or even better, in that folder or any folders within it) I\'d like to make some changes to the php settings. Can I jus

相关标签:
5条回答
  • 2020-12-21 09:17

    The .htaccess files are typically the best way to go for an Apache server. However, to answer your original question, yes you can set a php.ini file in every directory if you want. However, in order for it to work, PHP must be set to run as PHP-CGI. My guess is that you are running PHP as an Apache module.

    See this link for reference on where PHP looks for php.ini and when it looks for it: http://www.php.net/manual/en/configuration.file.php

    0 讨论(0)
  • 2020-12-21 09:17

    instead of modifying php.ini file for each folder you would be required to modify a .htaccess file. Keep the file in the folders with whatever setting you like. You cant do this with a php.ini file since changes in php.ini are considered server wide

    0 讨论(0)
  • 2020-12-21 09:23

    You'll have to use a .htaccess file for that. There a section in the PHP manual about that:

    http://php.net/manual/en/configuration.changes.php

    For more general information on htaccess files you can read:

    http://en.wikipedia.org/wiki/Htaccess

    or

    http://httpd.apache.org/docs/2.0/howto/htaccess.html

    0 讨论(0)
  • 2020-12-21 09:28

    You could also use ini_set(), if you wanted to do it in code.

    0 讨论(0)
  • 2020-12-21 09:32

    It looks like you're wanting to use per-directory php.ini files which are available as of PHP 5.3. If it's your own server, I'd like to think you're happy to keep up with the latest stable releases (currently 5.3.2). Back to ini files, to quote that manual page:

    Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on a per-directory basis. These files are processed only by the CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are using Apache, use .htaccess files for the same effect.

    In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognized in .user.ini-style INI files.

    0 讨论(0)
提交回复
热议问题