Windows 10 安装 Magento 2.3 后管理页面空白

Blank admin page after installing Magento 2.3 on Windows 10

我正在使用 xampp 在 Windows 10 上本地安装 Magento 2.3。我从 Github 下载存档,解压缩到 c:\xampp\htdocs\magento2,并在我的浏览器中从 localhost/magento2/setup 下载 运行 安装程序。

安装程序完成,没有任何错误,但是当我转到管理页面时,我看到一个背景为灰色的空白页面。当我去 localhost/magento2 时,我得到这个

当我查看 magento2/var/log/system.log 时,出现了一些类似以下内容的错误(对于不同文件名的列表,这些错误中的每一个都会重复多次)

main.ERROR: A symlink for "C:/xampp/htdocs/magento2/lib/web/requirejs/require.js" can't be created and placed to "C:/xampp/htdocs/magento2/pub/static/adminhtml/Magento/backend/en_US/requirejs/require.js". Warning!symlink(): Cannot create symlink, error code(1314) [] [] ) [] []

main.CRITICAL: Invalid template file: 'C:/xampp/htdocs/magento2/app/code/Magento/Backend/view/adminhtml/templates/page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js' [] []

编辑:

我通过更改 magento\lib\internal\Magento\Framework\View\Element\Template\File\Validator.php

中的代码使管理页面正常工作

原代码是

public function isValid($filename)
{
    $filename = str_replace('\', '/', $filename);
    if (!isset($this->_templatesValidationResults[$filename])) {
        $this->_templatesValidationResults[$filename] =
            ($this->isPathInDirectories($filename, $this->_compiledDir)
                || $this->isPathInDirectories($filename, $this->moduleDirs)
                || $this->isPathInDirectories($filename, $this->_themesDir)
                || $this->_isAllowSymlinks)
            && $this->getRootDirectory()->isFile($this->getRootDirectory()->getRelativePath($filename));
    }
    return $this->_templatesValidationResults[$filename];
}

我改成了

public function isValid($filename)
{
   return true;
}

因为我是 Magento 的新手,所以我不明白这个方法应该做什么(我假设它正在验证模板文件,但我不知道如何或在哪里)。此外,当我在原始代码中添加一条日志语句以显示 $this->_templatesValidationResults[$filename] 的内容时(就在 return 语句之前),它打印了几个空数组元素。例如,它打印了

[] []  
[] []
[] []
[] []

Magento 似乎认为模板文件无效,但没有说明它们无效的任何原因。我这样说对吗?我该如何阻止 Magento 错误地将模板文件检测为无效,或者获取正确的验证错误消息?

可能的解决方案,以及进一步的问题

我将问题追溯到文件 magento\lib\internal\Magento\Framework\View\Element\Template\File\Validator.php

函数

protected function isPathInDirectories($path, $directories)
{
    if (!is_array($directories)) {
        $directories = (array)$directories;
    }
    $realPath = $this->fileDriver->getRealPath($path);
    foreach ($directories as $directory) {
        if (0 === strpos($realPath, $directory)) {
            return true;
        }
    }
    return false;
}

问题在于 $path 中有正斜杠,但 $realPath 中有反斜杠,因此 strpos 永远不会 returns 匹配,函数总是 returns假的。我将函数更新为

protected function isPathInDirectories($path, $directories)
{
    if (!is_array($directories)) {
        $directories = (array)$directories;
    }
    $realPath = $this->fileDriver->getRealPath($path);
    foreach ($directories as $directory) {
        if (0 === strpos($realPath, $directory) || 0 === strpos($path, $directory)) {
            return true;
        }
    }
    return false;
}

现在可以了。我认为这是一个 Windows-only 问题?这是 Magento 中没有考虑 Windows 文件命名的错误,还是我在设置中做错了什么?

我在 Windows 10 上使用 magento 2.3 时遇到同样的问题,后台页面显示棕色背景的空白页面。

在网上搜索问题后,终于找到了解决方法

  1. 在 magento 安装目录中打开文件 /vendor/magento/framework/View/Element/Template/File/Validator.php,找到

    $realPath = $this->fileDriver->getRealPath($path);

替换为:

$realPath = str_replace('\', '/', $this->fileDriver->getRealPath($path));

终于显示登录页面,但是登录页面和登录后都没有图标

  1. 在magento安装目录中打开文件app/etc/di.xml,找到

    Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink

并替换为

Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
  1. 然后前往var/cache,删除所有文件夹/文件
  2. 刷新页面,完成。