部署Magento可能会遇到的问题集合
一 访问页面现500错误
查看了一下apache的日志
.htaccess: Invalid command '<IfVersion', perhaps misspelled or defined by a module not included in the server configuration, referer: http://xxx/info.php
这是缺失了Apache "mod_version"模块引起的,只需要启用该模块就可以了。
二 Autoload error
Vendor autoload is not found. Please run 'composer install' under application root directory.
这时候你需要安装和配置composer
,然后在命令行切换到项目根目录,然后输入 composer install
三 后台空白
在安装完成后登录后台后一片空白,无任何内容,用Chrome F12调试会发现前端出现大量类似这样的错误:
Refused to execute script from '<URL>' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
在项目目录/var/log
中可以看到php错误:
main.CRITICAL: Invalid template file: 'PATHTO/app/code/Magento/Backend/view/adminhtml/templates/page/copyright.phtml' in module: 'Magento_Backend' block's name: 'copyright' [] []
解决方法
Magento 2.3.0
修改文件 #\lib\internal\Magento\Framework\View\Element\Template\File\Validator.php:138
,
切记,注意这里的文件位置,Google的搜索结果中mangento官方社区、Github、Stackoverflow大多提供的目录(#/vendor/magento/framework/View/Element/Template/File/Validator.php:114
)都是错误的!
找到这一行:
$realPath = $this->fileDriver->getRealPath($path);
替换为
$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
Magento 2.2.7
修改文件 /vendor/magento/framework/View/Element/Template/File/Validator.php:113
找到
protected function isPathInDirectories($path, $directories) { if (!is_array($directories)) { $directories = (array)$directories; } foreach ($directories as $directory) { if (0 === strpos($this->fileDriver->getRealPath($path), $directory)) { return true; } } return false; }
替换为
protected function isPathInDirectories($path, $directories) { $realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path)); if (!is_array($directories)) { $directories = (array)$directories; } foreach ($directories as $directory) { if (0 === strpos($realPath, $directory)) { return true; } } return false; }
四 前台空白
前台空白引起的原因和后台是如出一辙,在按照前面的后台空白解决的解决方法解决了后台问题之后只需要登录到后台 System -> Tools -> Cache Management
清空一下缓存就可以访问了。
[2019-07-22 03:13:18] main.INFO: Add of item with id Magento_Sitemap::catalog_sitemap was processed [] [] [2019-07-22 03:13:18] main.INFO: Add of item with id Magento_Tax::sales_tax was processed [] [] [2019-07-22 03:13:18] main.INFO: Add of item with id Magento_Tax::sales_tax_rules was processed [] [] [2019-07-22 03:13:18] main.INFO: Add of item with id Magento_Tax::sales_tax_rates was processed [] [] [2019-07-22 03:13:18] main.INFO: Add of item with id Magento_TaxImportExport::system_convert_tax was processed [] [] [2019-07-22 03:13:18] main.INFO: Add of item with id Magento_Braintree::settlement_report was processed [] []