windows安装magento2.3出现的问题和解决办法
7天成为Magento系统架构师,现在开始学习Magento全栈开发!
《Magento2.X企业级开发实战》
前言:
最近看网站的搜索引擎关键词记录,发现一个问题搜索的特别多,就是Windows安装magento2.3。
搜索指定版本是2.3的。
一直在虚拟机里面测试magento,所以都没碰到过这个问题。自己亲自测试了下,安装过程中一切正常,操作跟magento2其他版本一样。但打开首页就开始报如下错误:
1 exception(s):
Exception #0 (MagentoFrameworkExceptionValidatorException): Invalid template file: 'D:/wwwroot/magento2.top/vendor/magento/module-theme/view/frontend/templates/page/js/require_js.phtml' in module: '' block's name: 'require.js'
Exception #0 (MagentoFrameworkExceptionValidatorException): Invalid template file: 'D:/wwwroot/magento2.top/vendor/magento/module-theme/view/frontend/templates/page/js/require_js.phtml' in module: '' block's name: 'require.js'
#0 D:wwwrootmagento2.topvendormagentoframeworkViewElementTemplate.php(301): MagentoFrameworkViewElementTemplate->fetchView('D:/wwwroot/mage...')
#1 D:wwwrootmagento2.topvendormagentoframeworkViewElementAbstractBlock.php(668): MagentoFrameworkViewElementTemplate->_toHtml()
#2 D:wwwrootmagento2.topvendormagentoframeworkViewResultPage.php(249): MagentoFrameworkViewElementAbstractBlock->toHtml()
查看日记文件 var/log/system.log
也有如下的报错信息
[2019-03-28 15:50:06] main.CRITICAL: Invalid template file: 'D:/wwwroot/magento2.top/vendor/magento/module-theme/view/frontend/templates/messages.phtml' in module: '' block's name: 'messages' [] []
[2019-03-28 15:50:06] main.CRITICAL: Invalid template file: 'D:/wwwroot/magento2.top/vendor/magento/module-customer/view/frontend/templates/account/authentication-popup.phtml' in module: 'Magento_Customer' block's name: 'authentication-popup' [] []
[2019-03-28 15:50:06] main.CRITICAL: Invalid template file: 'D:/wwwroot/magento2.top/vendor/magento/module-customer/view/frontend/templates/js/section-config.phtml' in module: 'Magento_Customer' block's name: 'customer.section.config' [] []
[2019-03-28 15:50:06] main.CRITICAL: Invalid template file: 'D:/wwwroot/magento2.top/vendor/magento/module-customer/view/frontend/templates/js/customer-data.phtml' in module: 'Magento_Customer' block's name: 'customer.customer.data' [] []
[2019-03-28 15:50:06] main.CRITICAL: Invalid template file: 'D:/wwwroot/magento2.top/vendor/magento/module-customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml' in module: 'Magento_Customer' block's name: 'customer.data.invalidation.rules' [] []
[2019-03-28 15:50:06] main.CRITICAL: Invalid template file: 'D:/wwwroot/magento2.top/vendor/amzn/amazon-pay-and-login-with-amazon-core-module/view/frontend/templates/config.phtml' in module: 'Amazon_Core' block's name: 'amazon_config' [] []
[2019-03-28 15:50:06] main.CRITICAL: Invalid template file: 'D:/wwwroot/magento2.top/vendor/magento/module-page-cache/view/frontend/templates/javascript.phtml' in module: 'Magento_PageCache' block's name: 'pageCache' [] []
[2019-03-28 15:50:06] main.CRITICAL: Invalid template file: 'D:/wwwroot/magento2.top/vendor/magento/module-catalog/view/frontend/templates/product/compare/sidebar.phtml' in module: '' block's name: 'catalog.compare.sidebar' [] []
[2019-03-28 15:50:06] main.CRITICAL: Invalid template file: 'D:/wwwroot/magento2.top/vendor/magento/module-wishlist/view/frontend/templates/sidebar.phtml' in module: 'Magento_Wishlist' block's name: 'wishlist_sidebar' [] []
[2019-03-28 15:50:06] main.CRITICAL: Invalid template file: 'D:/wwwroot/magento2.top/vendor/magento/module-newsletter/view/frontend/templates/subscribe.phtml' in module: 'Magento_Newsletter' block's name: 'form.subscribe' [] []
问题产生原因
大概就是说magento2.3后不建议也不支持在windows上面部署
但开发还是用windows比较多的,所以问题很早就有人碰到了。解决起来也简单
解决办法
找到并修改类文件 MagentoFrameworkViewElementTemplateFileValidator
注意:官网下载的打包程序和Git上获取的程序文件路径不一样。
protected function isPathInDirectories($path, $directories)
{
if (!is_array($directories)) {
$directories = (array)$directories;
}
$realPath = $this->fileDriver->getRealPath($path);
// 添加下面这一行
$realPath = str_replace('\', '/', $realPath);
foreach ($directories as $directory) {
if (0 === strpos($realPath, $directory)) {
return true;
}
}
return false;
}
修改后测试验证
- 设置开发模式
php bin/magento deploy:mode:set developer
- 清除/generated/目录下的文件
- 制生成静态资源文件
由于我现在没有配置本地的开发环境,这里强制生成静态资源文件
php bin/magento setup:static-content:deploy -f
到这里,打开网站就能正常了。
参考资料 https://magento.stackexchange.com/questions/251946/magento-2-3-problems-on-local-server
文章来源于互联网:windows安装magento2.3出现的问题和解决办法
如无特殊说明或标注,任何个人或组织,复制、转载、采集本站内容请注明:
本文来源于:【Magento中文网】,并添加本文地址链接。
如未按上述操作复制或转载,本站有权追究法律责任。
若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
本文来源于:【Magento中文网】,并添加本文地址链接。
如未按上述操作复制或转载,本站有权追究法律责任。
若本站内容侵犯了原著者的合法权益,可联系我们进行处理。