首页 > 解决方案 > 尝试设置 XAMPP (Windows) 以并行支持两个 PHP 版本

问题描述

我在包含 PHP 8 的 Windows 10 (xampp-windows-x64-8.0.10-0-VS16) 上成功运行 XAMPP。现在我需要处理一些尚未准备好 PHP 8 的旧项目。找到几篇文章解释了如何设置环境以支持两个版本的 PHP。我按照Is there way to use two PHP versions in XAMPP? ,特别是在标题为“当您可以通过单个 xampp 安装同时使用多个 PHP 版本时为什么在 PHP 版本之间切换?”的答案中,选项 1仅对特定目录使用 PHP 7.4

我无法让它工作。这是我到目前为止所做的:

  1. 从php.net下载 PHP 7.4 (VC15 x64 Non Thread Safe (2021-Sep-21 16:58:34)) ,并将 zip 解压到“xampp”目录下的新目录“php74”,即d:\xamp \php74
  2. 在 *php74" 中创建文件php.ini,并对其进行修改。
  3. 按照说明编辑了http-xampp.conf文件。

通过此设置(请参阅下面的配置文件),PHP 8 就绪的网站(仍然)正确显示在 brwoser 中。

访问localhost/photos-local-dev/时,我可以看到 Apache 正在尝试为该网站运行 PHP 7.4,因为之前的错误消息...Call to undefined function get_magic_quotes_gpc()...不再显示。因此httpd-xampp.conf中的新指令处于活动状态。

然而,浏览器没有将index.php传递给 PHP 7.4,而是简单地将index.php文件显示为(几乎)纯文本文件(不要看换行符;出于可读性原因,我重新格式化了一点):

0 && $page['start']>=count($page['items'])) { page_not_found('', duplicate_index_url(array('start'=>0))); } 
trigger_notify('loc_begin_index');//---------------------------------------------- change of image display order 
if (isset($_GET['image_order'])) { if ( (int)$_GET['image_order'] > 0){pwg_set_session_var('image_order', 
(int)$_GET['image_order']); } else {pwg_unset_session_var('image_order'); } redirect( duplicate_index_url( array(),//
nothing to redefine array('start') // changing display order goes back to section first page ) ); } if(isset(
$_GET['display'])) { $page['meta_robots']['noindex']=1; if (array_key_exists($_GET['display'],
ImageStdParams::get_defined_type_map())) {pwg_set_session_var('index_deriv', $_GET['display']); } } 
//-------------------------------------------------------------- initialization // navigation bar $page[
'navigation_bar'] = array(); if (count($page['items']) > $page['nb_image_page']) { $page['navigation_bar'] = 
create_navigation_bar( duplicate_index_url(array(), array('start')), count($page['items']), 

在尝试查找问题时,我偶然发现了httpd-xampp.conf中的以下几行:

<IfModule env_module>
    SetEnv MIBDIRS "D:/xampp/php/extras/mibs"
    SetEnv MYSQL_HOME "\\xampp\\mysql\\bin"
    SetEnv OPENSSL_CONF "D:/xampp/apache/bin/openssl.cnf"
    SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php"
    SetEnv PHPRC "\\xampp\\php"
    SetEnv TMP "\\xampp\\tmp"
</IfModule>

#
# PHP-Module setup
#
LoadFile "D:/xampp/php/php8ts.dll"
LoadFile "D:/xampp/php/libpq.dll"
LoadFile "D:/xampp/php/libsqlite3.dll"
LoadModule php_module "D:/xampp/php/php8apache2_4.dll"

如果我停用LoadFileLoadModule行,然后尝试再次显示 PHP 8 就绪的网站,则浏览器会将index.php显示为文本,如上所示。这证实了这些负载是必不可少的。那么,我可以添加指向 PHP 7.4 模块的相应指令吗?Apache如何区分?但是,唉,模块php7ts.dllphp7apach2_4.dll甚至不存在于 PHP74 目录中?这些必须是 xampp 提供的 PHP 附加组件,因为在官方 zip 文件中找不到它们。

有人真的让这个工作吗?对上述堆栈溢出问答的一些评论似乎表明了这一点。

那么,我错过了什么?

这是httpd-xamp.conf

#
# XAMPP settings
#

<IfModule env_module>
    SetEnv MIBDIRS "D:/xampp/php/extras/mibs"
    SetEnv MYSQL_HOME "\\xampp\\mysql\\bin"
    SetEnv OPENSSL_CONF "D:/xampp/apache/bin/openssl.cnf"
    SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php"
    SetEnv PHPRC "\\xampp\\php"
    SetEnv TMP "\\xampp\\tmp"
</IfModule>

#
# PHP-Module setup
#
LoadFile "D:/xampp/php/php8ts.dll"
LoadFile "D:/xampp/php/libpq.dll"
LoadFile "D:/xampp/php/libsqlite3.dll"
LoadModule php_module "D:/xampp/php/php8apache2_4.dll"

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

<IfModule php_module>
    PHPINIDir "D:/xampp/php"
</IfModule>

<IfModule mime_module>
    AddType text/html .php .phps
</IfModule>

ScriptAlias /php-cgi/ "D:/xampp/php/"
<Directory "D:/xampp/php">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
          Require all granted
    </Files>
</Directory>

# Added by phun to support PHP 7.4 in parallel to PHP 8 that came with xampp
# |
ScriptAlias /php74 "D:/xampp/php74/"
Action application/x-httpd-php74-cgi /php74/php-cgi.exe
<Directory "D:/xampp/php74">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
          Require all granted
    </Files>
</Directory>
# |
# Added by phun to support PHP 7.4 in parallel to PHP 8 that came with xampp

<Directory "D:/xampp/cgi-bin">
    <FilesMatch "\.php$">
        SetHandler cgi-script
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler None
    </FilesMatch>
</Directory>

<Directory "D:/xampp/htdocs/xampp">
    <IfModule php_module>
        <Files "status.php">
            php_admin_flag safe_mode off
        </Files>
    </IfModule>
    AllowOverride AuthConfig
</Directory>

<IfModule alias_module>
    Alias /licenses "D:/xampp/licenses/"
    <Directory "D:/xampp/licenses">
        Options +Indexes
        <IfModule autoindex_color_module>
            DirectoryIndexTextColor  "#000000"
            DirectoryIndexBGColor "#f8e8a0"
            DirectoryIndexLinkColor "#bb3902"
            DirectoryIndexVLinkColor "#bb3902"
            DirectoryIndexALinkColor "#bb3902"
        </IfModule>
        Require local
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
   </Directory>

    Alias /phpmyadmin "D:/xampp/phpMyAdmin/"
    <Directory "D:/xampp/phpMyAdmin">
        AllowOverride AuthConfig
        Require local
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    </Directory>

    Alias /webalizer "D:/xampp/webalizer/"
    <Directory "D:/xampp/webalizer">
        <IfModule php_module>
            <Files "webalizer.php">
                php_admin_flag safe_mode off
            </Files>
        </IfModule>
        AllowOverride AuthConfig
        Require local
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    </Directory>
</IfModule>

# Added by phun to support PHP 7.4 in parallel to PHP 8 that came with xampp
# |
<Directory "D:\xampp\htdocs\photos-local-dev">
    UnsetEnv PHPRC
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php74
    </FilesMatch>
</Directory>
# |
# Added by phun to support PHP 7.4 in parallel to PHP 8 that came with xampp

这是精简的php.ini(删除了注释和空行):

[PHP]
engine=On
short_open_tag=Off
precision=14
output_buffering=4096
zlib.output_compression=Off
implicit_flush=Off
unserialize_callback_func=
serialize_precision=-1
disable_functions=
disable_classes=
zend.enable_gc=On
zend.exception_ignore_args=Off
zend.exception_string_param_max_len=15
expose_php=On
max_execution_time=120
max_input_time=60
memory_limit=512M
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors=On
display_startup_errors=On
log_errors=On
log_errors_max_len=1024
ignore_repeated_errors=Off
ignore_repeated_source=Off
report_memleaks=On
variables_order="GPCS"
request_order="GP"
register_argc_argv=Off
auto_globals_jit=On
post_max_size=40M
auto_prepend_file=
auto_append_file=
default_mimetype="text/html"
default_charset="UTF-8"
doc_root=
user_dir=
extension_dir="D:\xampp\php74\ext"
enable_dl=Off
file_uploads=On
upload_tmp_dir="D:\xampp\tmp"
upload_max_filesize=40M
max_file_uploads=20
allow_url_fopen=On
allow_url_include=Off
default_socket_timeout=60
extension=bz2
extension=curl
extension=fileinfo
extension=gd
extension=gettext
extension=mbstring
extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
extension=pdo_mysql
extension=pdo_sqlite
asp_tags=Off
display_startup_errors=On
track_errors=Off
y2k_compliance=On
allow_call_time_pass_reference=Off
safe_mode=Off
safe_mode_gid=Off
safe_mode_allowed_env_vars=PHP_
safe_mode_protected_env_vars=LD_LIBRARY_PATH
error_log="D:\xampp\php\logs\php_error_log"
register_globals=Off
register_long_arrays=Off
magic_quotes_gpc=Off
magic_quotes_runtime=Off
magic_quotes_sybase=Off
extension=php_openssl.dll
extension=php_ftp.dll
[CLI Server]
cli_server.color=On
[Date]
[filter]
[iconv]
[imap]
[intl]
[sqlite3]
[Pcre]
[Pdo]
pdo_mysql.default_socket="MySQL"
[Pdo_mysql]
pdo_mysql.default_socket=
[Phar]
[mail function]
SMTP=localhost
smtp_port=25
mail.add_x_header=Off
[ODBC]
odbc.allow_persistent=On
odbc.check_persistent=On
odbc.max_persistent=-1
odbc.max_links=-1
odbc.defaultlrl=4096
odbc.defaultbinmode=1
[MySQLi]
mysqli.max_persistent=-1
mysqli.allow_persistent=On
mysqli.max_links=-1
mysqli.default_port=3306
mysqli.default_socket=
mysqli.default_host=
mysqli.default_user=
mysqli.default_pw=
mysqli.reconnect=Off
[mysqlnd]
mysqlnd.collect_statistics=On
mysqlnd.collect_memory_statistics=On
[OCI8]
[PostgreSQL]
pgsql.allow_persistent=On
pgsql.auto_reset_persistent=Off
pgsql.max_persistent=-1
pgsql.max_links=-1
pgsql.ignore_notice=0
pgsql.log_notice=0
[bcmath]
bcmath.scale=0
[browscap]
[Session]
session.save_handler=files
session.save_path="D:\xampp\tmp"
session.use_strict_mode=0
session.use_cookies=1
session.use_only_cookies=1
session.name=PHPSESSID
session.auto_start=0
session.cookie_lifetime=0
session.cookie_path=/
session.cookie_domain=
session.cookie_httponly=
session.cookie_samesite=
session.serialize_handler=php
session.gc_probability=1
session.gc_divisor=1000
session.gc_maxlifetime=1440
session.referer_check=
session.cache_limiter=nocache
session.cache_expire=180
session.use_trans_sid=0
session.sid_length=26
session.trans_sid_tags="a=href,area=href,frame=src,form="
session.sid_bits_per_character=5
[Assertion]
zend.assertions=1
[COM]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output=Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit=5
[sysvshm]
[ldap]
ldap.max_links=-1
[dba]
[opcache]
[curl]
curl.cainfo="D:\xampp\apache\bin\curl-ca-bundle.crt"
[openssl]
openssl.cafile="D:\xampp\apache\bin\curl-ca-bundle.crt"
[ffi]
[Syslog]
define_syslog_variables=Off
[Session]
define_syslog_variables=Off
[Date]
date.timezone=Europe/Berlin
[MySQL]
mysql.allow_local_infile=On
mysql.allow_persistent=On
mysql.cache_size=2000
mysql.max_persistent=-1
mysql.max_link=-1
mysql.default_port=3306
mysql.default_socket="MySQL"
mysql.connect_timeout=3
mysql.trace_mode=Off
[Sybase-CT]
sybct.allow_persistent=On
sybct.max_persistent=-1
sybct.max_links=-1
sybct.min_server_severity=10
sybct.min_client_severity=10
[MSSQL]
mssql.allow_persistent=On
mssql.max_persistent=-1
mssql.max_links=-1
mssql.min_error_severity=10
mssql.min_message_severity=10
mssql.compatability_mode=Off
mssql.secure_connection=Off

标签: phpwindowsapachexampp

解决方案


推荐阅读