具有多个 PHP 版本的 XAMPP 中的 <Virtual Host>
Posted
技术标签:
【中文标题】具有多个 PHP 版本的 XAMPP 中的 <Virtual Host>【英文标题】:<VirtualHost> in XAMPP with multiples PHP versions 【发布时间】:2021-09-12 16:04:42 【问题描述】:我最近已经发布了一个关于在 Windows 10 上的 XAMPP 7.4.16 服务器上运行多个版本的 php 的问题。起初它工作正常并且没有问题。 它的工作原理是这样的:
8088 端口上的 PHP 8 PHP 7.4 端口 80(默认) PHP 7.3 端口 8083 PHP 7.2 端口 8082 PHP 7.1 端口 8081 PHP 7.0 端口 8080 PHP 5.6 端口 8056
现在我需要创建一个 VirtualHost 来将域关联到在 Zend Framework 中开发的应用程序,但我没有成功。它是在 PHP 5.6 中开发的,我需要它来响应服务器上的 viderahome.local 域。
这是我的代码:
httpd.conf
LoadModule vhost_alias_module modules/mod_vhost_alias.so
httpd-xampp.conf
<IfModule env_module>
SetEnv MIBDIRS "C:/xampp/php/extras/mibs"
SetEnv mysql_HOME "\\xampp\\mysql\\bin"
SetEnv OPENSSL_CONF "C:/xampp/apache/bin/openssl.cnf"
SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php"
SetEnv PHPRC "\\xampp\\php"
SetEnv TMP "\\xampp\\tmp"
</IfModule>
LoadFile "C:/xampp/php/php7ts.dll"
LoadFile "C:/xampp/php/libpq.dll"
LoadFile "C:/xampp/php/libsqlite3.dll"
LoadModule php7_module "C:/xampp/php/php7apache2_4.dll"
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
<IfModule php7_module>
PHPINIDir "C:/xampp/php"
</IfModule>
<IfModule mime_module>
AddType text/html .php .phps
</IfModule>
ScriptAlias /php-cgi/ "C:/xampp/php/"
<Directory "C:/xampp/php">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
<Directory "C:/xampp/cgi-bin">
<FilesMatch "\.php$">
SetHandler cgi-script
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler None
</FilesMatch>
</Directory>
<Directory "C:/xampp/htdocs/xampp">
<IfModule php7_module>
<Files "status.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
<IfModule alias_module>
Alias /licenses "C:/xampp/licenses/"
<Directory "C:/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 "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
AllowOverride AuthConfig
Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
Alias /webalizer "C:/xampp/webalizer/"
<Directory "C:/xampp/webalizer">
<IfModule php7_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>
用于在特定端口运行某些 PHP 版本的虚拟主机
8088 端口中的 PHP 8.0
ScriptAlias /php_8.0 "C:/xampp/php_8.0"
<Directory "C:/xampp/php_8.0">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
Listen 8088
<VirtualHost *:8088>
UnsetEnv PHPRC
<FilesMatch "\.php$">
php_flag engine off
SetHandler application/x-httpd-php
Action application/x-httpd-php "/php_8.0/php-cgi.exe"
</FilesMatch>
</VirtualHost>
HP 7.3 在端口 8083
ScriptAlias /php_7.3 "C:/xampp/php_7.3"
<Directory "C:/xampp/php_7.3">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
Listen 8083
<VirtualHost *:8083>
UnsetEnv PHPRC
<FilesMatch "\.php$">
php_flag engine off
SetHandler application/x-httpd-php
Action application/x-httpd-php "/php_7.3/php-cgi.exe"
</FilesMatch>
</VirtualHost>
PHP 7.2 在端口 8082
ScriptAlias /php_7.2 "C:/xampp/php_7.2"
<Directory "C:/xampp/php_7.2">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
Listen 8082
<VirtualHost *:8082>
UnsetEnv PHPRC
<FilesMatch "\.php$">
php_flag engine off
SetHandler application/x-httpd-php
Action application/x-httpd-php "/php_7.2/php-cgi.exe"
</FilesMatch>
</VirtualHost>
PHP 7.1 在端口 8081
ScriptAlias /php_7.1 "C:/xampp/php_7.1"
<Directory "C:/xampp/php_7.1">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
Listen 8081
<VirtualHost *:8081>
UnsetEnv PHPRC
<FilesMatch "\.php$">
php_flag engine off
SetHandler application/x-httpd-php
Action application/x-httpd-php "/php_7.1/php-cgi.exe"
</FilesMatch>
</VirtualHost>
PHP 7.0 在端口 8080
ScriptAlias /php_7.0 "C:/xampp/php_7.0"
<Directory "C:/xampp/php_7.0">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
Listen 8080
<VirtualHost *:8080>
UnsetEnv PHPRC
<FilesMatch "\.php$">
php_flag engine off
SetHandler application/x-httpd-php
Action application/x-httpd-php "/php_7.0/php-cgi.exe"
</FilesMatch>
</VirtualHost>
端口 8056 中的 PHP 5.6
ScriptAlias /php_5.6 "C:/xampp/php_5.6"
<IfModule actions_module>
Action application/x-httpd-php56-cgi "/php_5.6/php-cgi.exe"
</IfModule>
<Directory "C:/xampp/php_5.6">
SetEnv PHPRC "C:/xampp/php_5.6"
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
Listen 8056
<VirtualHost *:8056>
<FilesMatch "\.php$">
SetHandler application/x-httpd-php56-cgi
</FilesMatch>
</VirtualHost>
httpd-vhost.conf
名称虚拟主机 *
<VirtualHost viderahome.local:8056>
DocumentRoot "D:\Dados\dados\htdocs\servicos\viderahome\www"
ServerName viderahome.local
ErrorLog "D:\Dados\dados\htdocs\servicos\viderahome\error.log"
CustomLog "D:\Dados\dados\htdocs\servicos\viderahome\access.log" combined
<Directory "D:\Dados\dados\htdocs\servicos\viderahome\www">
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
主机文件
C:\windows\system32\drivers\etc\hosts
127.0.0.1 viderahome.local www.viderahome.local
日志
错误日志
[Wed Jun 30 08:31:41.565771 2021] [php7:notice] [pid 8356:tid 2060] [client 127.0.0.1:60483] PHP Notice: compact(): Undefined variable: extras in D:\\Dados\\dados\\htdocs\\servicos\\viderahome\\library\\Zend\\View\\Helper\\HeadLink.php on line 393
[Wed Jun 30 08:31:41.565898 2021] [php7:notice] [pid 8356:tid 2060] [client 127.0.0.1:60483] PHP Notice: compact(): Undefined variable: extras in D:\\Dados\\dados\\htdocs\\servicos\\viderahome\\library\\Zend\\View\\Helper\\HeadLink.php on line 393
[Wed Jun 30 08:31:41.565898 2021] [php7:notice] [pid 8356:tid 2060] [client 127.0.0.1:60483] PHP Notice: compact(): Undefined variable: extras in D:\\Dados\\dados\\htdocs\\servicos\\viderahome\\library\\Zend\\View\\Helper\\HeadLink.php on line 393
[Wed Jun 30 08:31:41.565898 2021] [php7:notice] [pid 8356:tid 2060] [client 127.0.0.1:60483] PHP Notice: compact(): Undefined variable: extras in D:\\Dados\\dados\\htdocs\\servicos\\viderahome\\library\\Zend\\View\\Helper\\HeadLink.php on line 393
[Wed Jun 30 08:31:41.597514 2021] [php7:error] [pid 8356:tid 2060] [client 127.0.0.1:60483] PHP Fatal error: Uncaught Zend_Session_Exception: Zend_Session::start() - D:\\Dados\\dados\\htdocs\\servicos\\viderahome\\library\\Zend\\Session.php(Line:477): Error #2 session_start(): Failed to read session data: files (path: /tmp) in D:\\Dados\\dados\\htdocs\\servicos\\viderahome\\library\\Zend\\Session.php:490\nStack trace:\n#0 D:\\Dados\\dados\\htdocs\\servicos\\viderahome\\application\\Bootstrap.php(84): Zend_Session::start()\n#1 D:\\Dados\\dados\\htdocs\\servicos\\viderahome\\library\\Zend\\Application\\Bootstrap\\BootstrapAbstract.php(669): Bootstrap->_initSession()\n#2 D:\\Dados\\dados\\htdocs\\servicos\\viderahome\\library\\Zend\\Application\\Bootstrap\\BootstrapAbstract.php(622): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('session')\n#3 D:\\Dados\\dados\\htdocs\\servicos\\viderahome\\library\\Zend\\Application\\Bootstrap\\BootstrapAbstract.php(586): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap('session')\n#4 D:\\Dados\\dados\\htdocs\\servicos\\viderahome\\library\\Zend\\Application.php(355): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap(NU in D:\\Dados\\dados\\htdocs\\servicos\\viderahome\\library\\Zend\\Session.php on line 490
access.log
127.0.0.1 - - [30/Jun/2021:08:31:41 -0300] "GET / HTTP/1.1" 500 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
每次我在浏览器中运行 URL viderahome.local 时,它都会指向我的 Web 服务器的根目录,而不是 Zend 应用程序文件夹。
可能缺少什么?
最好的问候。
里卡多。
【问题讨论】:
尝试一次分解它,它是否适用于 2 个端口,3 个等。它在什么时候分解? 我通过添加端口号发现VirtualHost URL正常工作,即我访问时:viderahome.local:8056访问应用程序,但是我的PHP版本有问题.不是访问响应端口 8056 的 PHP 5.6,而是访问 XAMPP 安装的默认 PHP,即端口 80 上的 7.4。如何解决这个问题? 【参考方案1】:在配置文件的顶部有一个 SetEnv,其中 php 的路径是硬编码的。删除这里定义的环境变量,这样Apache就不会覆盖你的别名了
【讨论】:
以上是关于具有多个 PHP 版本的 XAMPP 中的 <Virtual Host>的主要内容,如果未能解决你的问题,请参考以下文章
如何在 MAC OS X 10.7 Lion 上安装多个 XAMPP 版本或多个 PHP 版本