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

Ben*_*bin 5 php magento2

我正在使用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];
}
Run Code Online (Sandbox Code Playgroud)

我将其更改为

public function isValid($filename)
{
   return true;
}
Run Code Online (Sandbox Code Playgroud)

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

[] []  
[] []
[] []
[] []
Run Code Online (Sandbox Code Playgroud)

看起来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;
}
Run Code Online (Sandbox Code Playgroud)

问题在于其中$path包含正斜杠,但$realPath具有反斜杠,因此,strpos永不返回匹配项,并且该函数始终返回false。我将功能更新为

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;
}
Run Code Online (Sandbox Code Playgroud)

现在就可以了。我认为这是仅Windows的问题?这是Magento中的错误,没有解决Windows文件命名问题吗?或者我在设置中做错了什么吗?

小智 12

我对Windows 10上的magento 2.3有同样的问题,后台页面显示空白页面为棕色背景。

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

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

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

用。。。来代替 :

$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
Run Code Online (Sandbox Code Playgroud)

最终显示登录页面,但登录页面和登录后缺少图标

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

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

并替换为

Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
Run Code Online (Sandbox Code Playgroud)
  1. 然后转到var / cache,删除所有文件夹/文件
  2. 刷新页面,完成。

  • 当前,此解决方案是破解核心代码以使其在Windows环境中正常工作的方法,但在将Magento更新到他们将其更改为原始版本或将其恢复为原始版本时,它将还原为2.3。当前的最佳实践是在Linux来宾操作系统中使用一种形式的虚拟机或类似vagrant的服务。这不是最快的方法,但却是保持工作的最佳方法,而不会通过将修补程序破解到核心代码中而使您的工作流在将来没有风险。 (3认同)