PHP运行于Apache 模块方式
当使用 PHP 作为 Apache 模块时,也可以用 Apache 的配置文件(例如 )和 cess 文件中的指令来修改 PHP 的配置设定。需要有“AllowOverride Options”或“AllowOverride All”权限才可以。
有几个 Apache 指令可以使用户在 Apache 配置文件内部修改 PHP 的配置。哪些指令属于 PHP_INI_ALL,PHP_INI_PERDIR 或 PHP_INI_SYSTEM 中的哪一个,请参考附录中的 配置选项列表。
php_value name value
设定指定的值。只能用于 PHP_INI_ALL 或 PHP_INI_PERDIR 类型的指令。要清除先前设定的值,把 value 设为 none。
Note: 不要用 php_value 设定布尔值。应该用 php_flag(见下面)。
php_flag name on|off
用来设定布尔值的配置指令。仅能用于 PHP_INI_ALL 和 PHP_INI_PERDIR 类型的指令。
php_admin_value name value
设定指定的指令的值。不能用于 cess 文件。任何用 php_admin_value 设定的指令都不能被 cess 或 virtualhost 中的指令覆盖。要清除先前设定的值,把 value 设为 none。
php_admin_flag name on|off
用来设定布尔值的配置指令。不能用于 cess 文件。任何用 php_admin_flag 设定的指令都不能被 cess 或 virtualhost 中的.指令覆盖。
Example #1 Apache 配置例子
<IfModule mod_php5.c>
php_value include_path ".:/usr/local/lib/php"
php_admin_flag engine on
</IfModule>
<IfModule mod_php4.c>
php_value include_path ".:/usr/local/lib/php"
php_admin_flag engine on
</IfModule>
Caution
PHP 常量不存在于 PHP 之外。例如在 中不能使用 PHP 常量如 E_ALL 或 E_NOTICE 来设定 error_reporting 指令,因为其无意义,实际等于 0。应该用相应的掩码值来替代。这些常量可以在 中使用。
通过 Windows 注册表修改 PHP 配置
在 Windows 下运行 PHP 时,可以用 Windows 注册表以目录为单位来修改配置。配置值存放于注册表项 HKLMSOFTWAREPHPPer Directory Values 下面,子项对应于路径名。例如对于目录 c:inetpubwwwroot 的配置值会存放于 HKLMSOFTWAREPHPPer Directory Valuescinetpubwwwroot 项下面。其中的设定对于任何位于此目录及其任何子目录的脚本都有效。项中的值的名称是 PHP 配置指令的名字,值的数据是字符串格式的指令值。值中的 PHP 常量不被解析。不过只有可修改范围是 PHP_INI_USER 的配置值可以用此方法设定,PHP_INI_PERDIR 的值就不行。
其它接口下的 PHP
无论怎样运行 PHP,都可以在脚本中通过 ini_set() 而在运行时修改某个值。更多信息见手册中 ini_set() 的页面。
如果对自己系统中的配置设定及其当前值的完整列表感兴趣,可以运行 phpinfo() 函数并查看其结果的页面。也可以在运行时用 ini_get() 或 get_cfg_var() 取得个别配置指令的值。
add a note add a note
User Contributed Notes 13 notes
up
down
3 Anteaus ?2 years ago
One of the most serious problems here is that it is hard to determine programmatically which of three or more possible configuration methods (, , cess) should be used on any given hosting company's server.
The worst outcome is if an routine attempts to set cess directives on a cgi-mode server, in which case the outcome is usually a '500' crash. Once in that situation the php installation routine cannot be rerun to correct the problem, so you effectively have a hosting lockout situation which can only be corrected by manual intervention.
up
down
-2 at gmail dot com ?9 years ago
Being able to put php directives in and have them work on a per-directory or per-vitual host basis is just great. Now there's another aspect which might be worth being aware of:
A directive put into your apache conf file applies to php when it runs as an apache module (i.e. in a web page), but NOT when it runs as CLI (command-line interface).
Such feature that might be unwanted by an unhappy few, but I guess most will find it useful. As far as I'm concerned, I'm really happy that I can use open_basedir in my file, and it restricts the access of web users and sub-admins of my domain, but it does NOT restrict my own command-line php scripts...
up
down
-3 nick at vistaworks dot net ?4 years ago
On Windows, as the documentation above states, you cannot set max_upload_filesize and post_max_size in the registry, because they are PHP_INI_PERDIR.
Confusingly, however, is the fact that phpinfo() will show your changes if you do add those to the regsitry, as if they were taking effect. However, the upload size is *not* changed, regardless of what phpinfo() reports.
I believe the reading of registry values and override happen 'too late' in the request processing, ie, after the file has already been uploaded and rejected.
In a perfect world, phpinfo() would recognize this and not report the overridden values, which is very confusing.
up
down
-4 Woody/mC ?9 years ago
@ pgl: As the documentation says:
"To clear a previously set value use none as the value."
Works fine for me.
up
down
-6 user at NOSPAM dot example dot com ?5 years ago
PHP Constants will work with php_value; for example:
-
为什么说结对编程实际操作起来很难
人们常说团结就是力量,那么在编程中人多是不是也能产生更高的效率呢?下面就和小编一起来看看吧!更多内容请关注应届毕业生网!结对编程有助于提高软件质量和加强团队成员合作。它有非常多的好处,但是,团队成员真的很容易结成对子吗?MarcosBrizeno,巴西ThoughtWorks...
-
php如何基于dom实现图书xml格式数据
导语:php如何基于dom实现图书xml格式数据呢?下面是小编给大家提供的代码实现方法,大家可以参考阅读,更多详情请关注应届毕业生考试网。<?php$doc=newDOMDocument();$doc->load('');$books=$doc->getElementsByTagName("book");foreach($booksas$book){$aut...
-
对PHP语言认识上要避免10大误区
PHP是一种非常流行的开源服务器端脚本语言,你在万维网看到的大多数网站都是使用php开发的。但是,你大概很奇怪的注意到有少部分的人发誓要离php远远的。但是令人更奇怪的是或者很震惊的说他们不用php并不是因为一些被证实的语言缺点。他们决定不用php,是因为误解...
-
php递归创建和删除文件夹的代码
php中递归创建和删除文件夹的代码,供大家学习参考。就跟随本站小编一起去了解下吧,想了解更多相关信息请持续关注我们应届毕业生考试网!方法一复制代码代码如下:<?php/***目录生成类:UtilsMakeDir*@authoryepeng*@since2010.3.18*/classUtilsMakeDir{//基目录建...