- 相關推薦
PHP運行于Apache 模塊方式
當使用 PHP 作為 Apache 模塊時,也可以用 Apache 的配置文件(例如 httpd.conf)和 .htaccess 文件中的指令來修改 PHP 的配置設定。需要有“AllowOverride Options”或“AllowOverride All”權限才可以。
有幾個 Apache 指令可以使用戶在 Apache 配置文件內部修改 PHP 的配置。哪些指令屬于 PHP_INI_ALL,PHP_INI_PERDIR 或 PHP_INI_SYSTEM 中的哪一個,請參考附錄中的 php.ini 配置選項列表。
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
設定指定的指令的值。不能用于 .htaccess 文件。任何用 php_admin_value 設定的指令都不能被 .htaccess 或 virtualhost 中的指令覆蓋。要清除先前設定的值,把 value 設為 none。
php_admin_flag name on|off
用來設定布爾值的配置指令。不能用于 .htaccess 文件。任何用 php_admin_flag 設定的指令都不能被 .htaccess 或 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 之外。例如在 httpd.conf 中不能使用 PHP 常量如 E_ALL 或 E_NOTICE 來設定 error_reporting 指令,因為其無意義,實際等于 0。應該用相應的掩碼值來替代。這些常量可以在 php.ini 中使用。
通過 Windows 注冊表修改 PHP 配置
在 Windows 下運行 PHP 時,可以用 Windows 注冊表以目錄為單位來修改配置。配置值存放于注冊表項 HKLM\SOFTWARE\PHP\Per Directory Values 下面,子項對應于路徑名。例如對于目錄 c:\inetpub\wwwroot 的配置值會存放于 HKLM\SOFTWARE\PHP\Per Directory Values\c\inetpub\wwwroot 項下面。其中的設定對于任何位于此目錄及其任何子目錄的腳本都有效。項中的值的名稱是 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 (php.ini, .user.ini, .htaccess) should be used on any given hosting company's server.
The worst outcome is if an install.php routine attempts to set .htaccess 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 contrees.du.reve at gmail dot com ?9 years ago
Being able to put php directives in httpd.conf 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 php.ini 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 httpd.conf 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:
php_value error_reporting 30711 #bitmask is the same as
php_value error_reporting "E_ALL & ~E_STRICT & ~E_NOTICE" #string of constants
up
down
-9 rohitkumar at cftechno dot com ?5 years ago
Open php.ini from c:/php in your text editor
If you installed Apache in the default location, the path should
be "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs". If you installed
it elsewhere, find the htdocs folder and type its path:
doc_root = "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs"
Just a little further down in the file, look for the line that begins with remove the semicolon from the start of the extension_
dir, and set it so that it points to the ext subfolder of your PHP folder:
extension_dir = "C:\PHP\ext"
These are optional extensions to PHP, disabled by default. We
want to enable the MySQL extension so that PHP can communicate with MySQL.
To do this, remove the semicolon from the start of the php_mysqli.dll line:
extension=php_mysqli.dll
note - php_mysqli, not php_mysql
Keep scrolling even further down in the file, and look for a line that starts with
;session.save_path. Once again, remove the semicolon to enable this line,
and set it to your Windows Temp folder:
session.save_path = "C:\Windows\Temp"
Browse to the conf subfolder in your Apache
installation folder (by default, C:\Program Files\Apache Software
Foundation\Apache2.2\conf), and select the httpd.conf file located there. In order
to make this file visible for selection, you’ll need to select All Files (*.*) from the
file type drop-down menu at the bottom of the Open window.
Look for the existing line in this file that begins with DirectoryIndex, shown
here:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
This line tells Apache which filenames to use when it looks for the default page
for a given directory. Add index.php to the end of this line:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
All of the remaining options in this long and intimidating configuration file
should have been set up correctly by the Apache install program. All you need
to do is add the following lines to the very end of the file:
LoadModule php5_module "C:/PHP/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/PHP"
Make sure the LoadModule and PHPIniDir lines point to your PHP installation
directory, and note the use of forward slashes (/) instead of backslashes (\) in
the paths.
Save your changes and Restart Apache using the Apache Service Monitor system tray icon. If all is
well, Apache will start up again without complaint.
up
down
-10 ohcc at 163 dot com ?3 years ago
You will fail if you try to change configuration settings of PHP with the php_value directive in Apache 2.4.
up
down
-10 andy at ddtechnologies dot com ?3 years ago
Registry Key Handling Through PHP:
This is an ready to use code. You just need to copy this code into a PHP file.
//php Code starts from here......
//Reading the Registry
$Wshshell= new COM('WScript.Shell');
$data= $Wshshell->regRead('HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip\path');
echo "Data is::".$data;
//Function for writing to the registry.
function registry_write($folder, $key, $value, $type="REG_SZ")
{
$WshShell = new COM("WScript.Shell");
$registry = "HKEY_LOCAL_MACHINE\\SOFTWARE\\" . $folder . "\\" . $key;
try{
$result = $WshShell->RegWrite($registry, $value, $type);
echo "Entry is Successfully written at:".$registry;
return($result);
}
catch(Exception $e){
echo "Some Exception in Registry writing".$e;
}
return false;
}
// Function to deleting from the Register Entry.
function registry_delete($folder, $key, $value, $type="REG_SZ")
{
$WshShell = new COM("Wscript.shell");
$registry = "HKEY_LOCAL_MACHINE\\SOFTWARE\\" . $folder . "\\" . $key;
try{
$result = $WshShell->RegDelete($registry);
echo $key." is Successfully deleted from HKEY_LOCAL_MACHINE\\SOFTWARE\\" . $folder ;
return($result);
}
catch(Exception $e){
echo "Some Exception with the code::".$e;
【PHP運行于Apache 模塊方式】相關文章:
php的常用運行方式07-23
php的常用運行方式是什么10-30
php的apache偽靜態09-28
php的4種常用運行方式詳解06-26
php虛擬主機Apache的配置方法09-28
Linux+Apache+Mysql+PHP優化技巧10-23
php怎么開啟openssl模塊08-04
PHP代碼運行流程08-14