XAMPP conf - 默认运行 php5_module 并根据 .htaccess 切换到其他 php cgi 版本
Posted
技术标签:
【中文标题】XAMPP conf - 默认运行 php5_module 并根据 .htaccess 切换到其他 php cgi 版本【英文标题】:XAMPP conf - Run php5_module per default & switch to other php cgi versions per .htaccess 【发布时间】:2014-07-11 02:03:54 【问题描述】:对于较旧的项目,我需要通过 .htacces 切换 php 版本。如果我只使用 php-cgi 版本,它会很好用。 php 作为模块具有更好的性能。现在我想将我的 xampp 配置为默认运行 php5_module 并在 htaccss 中使用 AddHandler ... 来切换到其他 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
【问题讨论】:
【参考方案1】:我找到了自己的解决方案:
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
【讨论】:
以上是关于XAMPP conf - 默认运行 php5_module 并根据 .htaccess 切换到其他 php cgi 版本的主要内容,如果未能解决你的问题,请参考以下文章