对于较旧的项目,我需要切换php版本到。htacces。它工作得很好,如果我只使用php-cgi版本。PHP作为模块具有更好的性能。现在我想配置我的xampp运行php5_module默认和使用AddHandler…在htaccess中切换到其他cgi版本的php。如何做到这一点?谢谢你的帮助。
xampp相依:
#
# XAMPP settings
#
<IfModule env_module>
SetEnv MIBDIRS "/xampplite/php/extras/mibs"
SetEnv MYSQL_HOME "\xampplite\mysql\bin"
SetEnv OPENSSL_CONF "/xampplite/apache/bin/openssl.cnf"
SetEnv PHP_PEAR_SYSCONF_DIR "\xampplite\php"
SetEnv PHPRC "\xampplite\php"
SetEnv TMP "\xampplite\tmp"
UnsetEnv PERL5LIB
</IfModule>
#
# PHP-Module setup
#
#LoadFile "/xampplite/php/php5ts.dll"
#LoadModule php5_module modules/php5apache2_2.dll
<IfModule php5_module>
<FilesMatch ".php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
PHPINIDir "/xampplite/php"
</IfModule>
#
# multible PHP Version Setup
#
#SetHandler application/x-httpd-php4
<IfModule !php5_module>
Action application/x-httpd-php4_3 "/php4_3/php.exe"
AddType application/x-httpd-php4_3 .php4 .php
Action application/x-httpd-php4_4 "/php4_4/php.exe"
AddType application/x-httpd-php4_4 .php4 .php
Action application/x-httpd-php5_4 "/php5_4/php.exe"
AddType application/x-httpd-php5_4 .php5 .php
Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
AddType application/x-httpd-php-cgi .php
<FilesMatch ".php$">
AddHandler application/x-httpd-php-cgi .php
# SetHandler application/x-httpd-php-cgi
</FilesMatch>
</IfModule>
ScriptAlias /php4_3/ "/xampplite/php4_3/"
<Directory "/xampplite/php4_3">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /php4_4/ "/xampplite/php4_4/"
<Directory "/xampplite/php4_4">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /php5_4/ "/xampplite/php5_4/"
<Directory "/xampplite/php5_4">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
#
# PHP-CGI setup
#
#<IfModule !php5_module>
# <FilesMatch ".php$">
# AddHandler application/x-httpd-php-cgi .php
# SetHandler application/x-httpd-php-cgi
# </FilesMatch>
# <IfModule actions_module>
# Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
# </IfModule>
#</IfModule>
<IfModule mime_module>
AddType text/html .php .phps
</IfModule>
ScriptAlias /php-cgi/ "/xampplite/php/"
<Directory "/xampplite/php">
AllowOverride None
Options None
Order deny,allow
Deny from all
<Files "php-cgi.exe">
Allow from all
</Files>
</Directory>
<Directory "/xampplite/cgi-bin">
<FilesMatch ".php$">
SetHandler cgi-script
</FilesMatch>
<FilesMatch ".phps$">
SetHandler None
</FilesMatch>
</Directory>
<Directory "/_projects/xampp">
<IfModule php5_module>
<Files "status.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
<IfModule alias_module>
Alias /security "/xampplite/security/htdocs/"
<Directory "/xampplite/security/htdocs">
<IfModule php5_module>
<Files "xamppsecurity.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
Alias /licenses "/xampplite/licenses/"
<Directory "/xampplite/licenses">
Options +Indexes
<IfModule autoindex_color_module>
DirectoryIndexTextColor "#000000"
DirectoryIndexBGColor "#f8e8a0"
DirectoryIndexLinkColor "#bb3902"
DirectoryIndexVLinkColor "#bb3902"
DirectoryIndexALinkColor "#bb3902"
</IfModule>
</Directory>
Alias /phpmyadmin "/xampplite/phpMyAdmin/"
<Directory "/xampplite/phpMyAdmin">
AllowOverride AuthConfig
</Directory>
Alias /webalizer "/xampplite/webalizer/"
<Directory "/xampplite/webalizer">
<IfModule php5_module>
<Files "webalizer.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
</IfModule>
#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Order deny,allow
Deny from all
Allow from ::1 127.0.0.0/8
fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16
fe80::/10 169.254.0.0/16
ErrorDocument 403 /error/HTTP_XAMPP_FORBIDDEN.html.var
</LocationMatch>
.htacces:
AddHandler application/x-httpd-php4_3 .php
SetHandler application/x-httpd-php4_3
#AddHandler application/x-httpd-php4_4 .php
#SetHandler application/x-httpd-php4_4
#AddHandler application/x-httpd-php5_4 .php
#SetHandler application/x-httpd-php5_4
我找到了自己的解决方案:
xampp参看
#
# XAMPP settings
#
<IfModule env_module>
SetEnv MIBDIRS "/xampplite/php/extras/mibs"
SetEnv MYSQL_HOME "\xampplite\mysql\bin"
SetEnv OPENSSL_CONF "/xampplite/apache/bin/openssl.cnf"
SetEnv PHP_PEAR_SYSCONF_DIR "\xampplite\php"
SetEnv PHPRC "\xampplite\php"
SetEnv TMP "\xampplite\tmp"
UnsetEnv PERL5LIB
</IfModule>
#
# PHP-Module setup (module as default version 5.3 in my case)
#
LoadFile "/xampplite/php/php5ts.dll"
LoadModule php5_module modules/php5apache2_2.dll
<IfModule php5_module>
<FilesMatch ".php$">
AddHandler application/x-httpd-php .php
#SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
PHPINIDir "/xampplite/php"
</IfModule>
#
# PHP-CGI multiple Version Setup
#
Action application/x-httpd-php4_3 "/php4_3/php.exe"
AddType application/x-httpd-php4_3 .php4 .php
Action application/x-httpd-php4_4 "/php4_4/php.exe"
AddType application/x-httpd-php4_4 .php4 .php
Action application/x-httpd-php5_4 "/php5_4/php-cgi.exe"
AddType application/x-httpd-php5_4 .php5 .php
Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
AddType application/x-httpd-php-cgi .php
<IfModule mime_module>
AddType text/html .php .phps
</IfModule>
ScriptAlias /php4_3/ "/xampplite/php4_3/"
<Directory "/xampplite/php4_3">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /php4_4/ "/xampplite/php4_4/"
<Directory "/xampplite/php4_4">
AllowOverride None
Options None
Order allow,deny
Allow from all
SetEnv PHPRC "\xampplite\php4_4"
</Directory>
ScriptAlias /php5_4/ "/xampplite/php5_4/"
<Directory "/xampplite/php5_4">
AllowOverride None
Options None
Order allow,deny
Allow from all
SetEnv PHP_PEAR_SYSCONF_DIR "\xampplite\php5_4"
SetEnv PHPRC "\xampplite\php5_4"
</Directory>
ScriptAlias /php-cgi/ "/xampplite/php/"
<Directory "/xampplite/php">
AllowOverride None
Options None
Order deny,allow
Deny from all
<Files "php-cgi.exe">
Allow from all
</Files>
</Directory>
<Directory "/xampplite/cgi-bin">
<FilesMatch ".php$">
SetHandler cgi-script
</FilesMatch>
<FilesMatch ".phps$">
SetHandler None
</FilesMatch>
</Directory>
<Directory "/_projects/xampp">
<IfModule php5_module>
<Files "status.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
<IfModule alias_module>
Alias /security "/xampplite/security/htdocs/"
<Directory "/xampplite/security/htdocs">
<IfModule php5_module>
<Files "xamppsecurity.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
Alias /licenses "/xampplite/licenses/"
<Directory "/xampplite/licenses">
Options +Indexes
<IfModule autoindex_color_module>
DirectoryIndexTextColor "#000000"
DirectoryIndexBGColor "#f8e8a0"
DirectoryIndexLinkColor "#bb3902"
DirectoryIndexVLinkColor "#bb3902"
DirectoryIndexALinkColor "#bb3902"
</IfModule>
</Directory>
Alias /phpmyadmin "/xampplite/phpMyAdmin/"
<Directory "/xampplite/phpMyAdmin">
AllowOverride AuthConfig
</Directory>
Alias /webalizer "/xampplite/webalizer/"
<Directory "/xampplite/webalizer">
<IfModule php5_module>
<Files "webalizer.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
</IfModule>
#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Order deny,allow
Deny from all
Allow from ::1 127.0.0.0/8
fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16
fe80::/10 169.254.0.0/16
ErrorDocument 403 /error/HTTP_XAMPP_FORBIDDEN.html.var
</LocationMatch>
如何使用。htaccess
#SetHandler application/x-httpd-php4_3
#SetHandler application/x-httpd-php4_4
SetHandler application/x-httpd-php5_4