# 常見問題
## 1,Incompatible argument type: Required type: \Magento\Framework\DB\AdapterInterface

把

改成

## 2,Fatal error: Allowed memory size of xxx
內存不足的話,需要修改php.ini配置文件
memory_limit 設為1024M
max_execution_time 設為360

## 3,The file "xxx/pub/media/tmp/catalog/product/i/n/index2_26.jpg" doesn't exist or not a file
上傳產品圖片報錯
在`php.ini`里面添加這個,
`upload_tmp_dir =pub/media/tmp`
就可以了
或者把產品刪了重新添加
## 4,recv() failed (104: Connection reset by peer) while reading response header from upstream
~~~
sudo vim /etc/php/7.0/fpm/pool.d/www.conf
~~~
添加
~~~
request_terminate_timeout = 7200s
~~~
保存后 重啟php7.0-fpm。
`request_terminate_timeout `:
表示每個到fastcgi的請求的超時時間,它的設計目的是為 在 php.ini 中的max_execution_time設置在某些特殊原因下不能終止 PHP 執行的情況。
于是,request_terminate_timeout 也就默默的成為限制 PHP 執行時間的另一個手段。
而request_terminate_timeout 和 max_execution_time 在一般情況下的關系是:
哪個值小,哪個起作用。。。
## 5,nginx 413 Request Entity Too Large
1,先排除`php.ini`的問題
打開`php.ini`,
把 `upload_max_filesize` 和 `post_max_size` 修改為20M,然后重啟。
2,排除nginx的問題
打開`/etc/nginx/nginx.conf`
在`http{}`段中加入 `client_max_body_size 20m;` 20m為允許最大上傳的大小。
保存后重啟nginx
## 6,magento/product-community-edition 2.2.4 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
這是缺少bcmath擴展庫,直接安裝即可
~~~
sudo apt-get install php7.0-bcmath
~~~
根據php版本來安裝。
`7.1`就是
~~~
sudo apt-get install php7.1-bcmath
~~~
`7.2`就是
~~~
sudo apt-get install php7.2-bcmath
~~~
## 7,后臺列表頁面一直轉 不顯示列表
這個是缺少js-translation.json文件的原因。
~~~
touch pub/static/adminhtml/Magento/backend/en_US/js-translation.json
~~~
這樣創建一個同名文件就行了。
這個文件只有在deploy的時候 才自動生成。
## 8,前后臺頁面都是亂的,沒樣式,deploy了N遍也不行。
這個問題 群里也遇到過,絕大部分都是`deploy`的語言包不是你網站設置的語言包。
什么意思呢?
本教程安裝的默認語言是美國英語,語言包名稱是`en_US`。
所以我deploy的時候 后面都是加的`setup:static-content:deploy en_US`。
那么如果你安裝的時候把默認語言選成英國英語了,英語英語的語言包名稱是`en_GB`。
那你`deploy`N遍`en_US`都沒用,要改成:
`bin/magento setup:static-content:deploy en_GB `。
也就是說要`deploy`英國英語語言包。
那么我怎么知道我默認語言的語言包是啥名字呢?
在后臺可以查看:
Stores->Configuration->General->Locale Options->Locale.

要對癥下藥!! 不要瞎`deploy`。
## 9,apache下頁面無樣式,deploy了N遍也不行
一般都是缺少pub/static/.htaccess的原因。
見
//bbs.mallol.cn/?thread-172.htm
## 10,Magento2頁面登陸后不能正確地獲取到登陸信息,但是有的頁面卻可以獲取登陸的session等信息。
這個問題主要是頁面緩存造成的,關閉頁面緩存接口,在頁面的layout中找到對應的xml配置文件,在block里加上cacheable=”false”即可解決。如:
~~~
<block class="Vendor\Module\Block\Something" cacheable="false"
name="something" template="Vendor_Module::something.phtml">
~~~
## 11,Magento2模塊和主題路徑
~~~
定制主題路徑 : app/design/frontend/
定制模塊路徑 : app/code/
默認主題路徑 : vendor/magento/theme-frontend-luma
默認模塊路徑 : vendor/magento/module-
可自定義, 如GreenTree
~~~
## 12,局域網內通過IP訪問測試主機192.168.1.117會跳轉到localhost域名, 解決辦法如下:
~~~
登錄Magento的后臺,Stores > Configuration > General > Web,展開Base URLs
修改 Magento 的 Base URLs 為 192.168.1.117即可
也可以通過表core_config_data修改
在path列里尋找
At web/unsecure/base_url
web/Secure/base_url
修改為對應的URL即可
~~~
## 13,module和component的區別是什么?
~~~
module是component的一種,一個component可以是:
一個模塊module(Magento2擴展/插件)
一個theme(magento2主題)
Language package(語言包)
~~~
## 14,Magento2頁面出現空白, 或者出現錯誤
很多情況下是文件權限問題或者緩存問題
可以通過清除緩存(包括瀏覽器緩存),更改文件權限解決
也可以清楚var/general下的所有文件,然后clean:cache
在安裝新的插件或者模塊的時候一定要注意文件的讀寫權限問題,
權限設置不當會導致站點生成靜態文件和緩存的時候出現有些文件生成失敗
導致網頁加載文件失敗,從而導致插件或組件功能異常
注意文件的權限常常是導致出現錯誤的原因
## 15,(InvalidArgumentException): Required parameter 'theme_dir' was not passed
主題丟失。
你把某個主題手動刪掉了,但是數據庫里沒刪,還有舊的主題記錄。
你需要找到`theme`表。
把那個主題記錄找到并刪除 就行了。
## 16,Something went wrong while saving this configuration: Area is already set
后臺上傳logo的時候 總是報這個錯。
這是2.2.4的一個bug。聽說2.2.5里修復了。
需要手動改下代碼:
找到 `Magento\Email\Model\AbstractTemplate.php`。
用composer安裝的一般在`vendor\magento\moduleemail\Model\AbstractTemplate.php`。
用github安裝的一般在
`app\code\Magento\Email\Model\AbstractTemplate.php`
把
~~~
public function setForcedArea($templateId)
{
if ($this->area) {
throw new \LogicException(__('Area is already set'));
}
$this->area = $this->emailConfig->getTemplateArea($templateId);
return $this;
}
~~~
改成
~~~
public function setForcedArea($templateId)
{
if (!isset($this->area)) {
$this->area = $this->emailConfig->getTemplateArea($templateId);
}
return $this;
~~~
保存代碼。
后臺測試上傳。應該就好了。
## 17,后臺登錄多次失敗,總是提示`Your current session has been expired`
執行命令:
~~~
php bin/magento config:set admin/security/session_lifetime 86400
php bin/magento cache:flush
~~~
然后再嘗試登錄 應該就好了。
見
https://github.com/magento/magento2/issues/5309
## 18,打開產品編輯頁面報錯
> Notice: Undefined offset: 0 in /var/www/magento2/vendor/magento/module-configurable-product/Model/Product/Type/VariationMatrix.php on line 43
這個一般是可配置產品子產品屬性的問題。
你應該是刪除了super attribute的某個option,導致他的子產品找不到屬性值 就報錯了。
解決辦法:
1,把$variationalAttributes變量打印出來
~~~
vim vendor/magento/module-configurable-product/Model/Product/Type/VariationMatrix.php
~~~
~~~
for ($attributeIndex = $attributesCount; $attributeIndex--;) {
$currentAttribute = $variationalAttributes[$attributeIndex];
$currentVariationValue = $currentVariation[$attributeIndex];
//add
if(!isset($currentAttribute['values'][$currentVariationValue])){
print_r($variationalAttributes);
var_dump($currentAttribute['values']);
die;
}
//end
$filledVariation[$currentAttribute['id']] = $currentAttribute['values'][$currentVariationValue];
}
~~~
找到values為空的屬性id。
比如:
~~~
Array
(
[0] => Array
(
[id] => 153
[values] => Array
(
)
)
[1] => Array
(
[id] => 151
[values] => Array
(
[0] => Array
(
[value] => 32
[label] => 7460
[price] => Array
(
[value_index] => 32
[label] => 7460
[product_super_attribute_id] => 1362
[default_label] => 7460
[store_label] => 7460
[use_default_value] => 1
)
)
~~~
說明id為153的屬性有問題。
2,`catalog_product_super_attribute`表刪除有問題的屬性
比如產品id為782,有問題的屬性id為153.
那么就在`catalog_product_super_attribute`表里搜索`product_id`為782的記錄。
把`attribute_id`為153的記錄刪掉就行了。
## 19,Exception\LocalizedException Key must not exceed 32 bytes
修改`app/etc/env.php`
查看下你的`key`是不是超過32個字符了,不能大于32個字符。超出了就改小點。

## 20,產品詳情頁面不顯示面包屑導航
見
//bbs.mallol.cn/?thread-183.htm
## Area code is not set

檢查下你調用的類。一般都是某個類代碼有問題。
## 21,Varnish 503(Backend Fetch Failed后端獲取失敗)
如果Magento2緩存標簽使用長度超過8192個字符,你可以看到HTTP 503(后臺讀取失敗)在瀏覽器中的錯誤。這些錯誤可能顯示如下:
~~~
Error 503 Backend fetch failed Backend fetch failed
Backend fetch failed
~~~
為了解決這個問題,修改varnish配置文件如下:
1.用 root 用戶打開:
CentOS 6: /etc/sysconfig/varnish
CentOS 7: /etc/varnish/varnish.params
Ubuntu: /etc/default/varnish
2,搜索 `http_resp_hdr_len` 參數
3,如果參數不存在增加 `thread_pool_max`
4,設置 `http_resp_hdr_len`
示例:`-p http_resp_hdr_len=64000 \`
代碼片段:
~~~
# DAEMON_OPTS is used by the init script.
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
-f ${VARNISH_VCL_CONF} \
-T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
-p thread_pool_min=${VARNISH_MIN_THREADS} \
-p thread_pool_max=${VARNISH_MAX_THREADS} \
-p http_resp_hdr_len=65536 \
-p http_resp_size=98304 \
-p workspace_backend=98304 \
-S ${VARNISH_SECRET_FILE} \
-s ${VARNISH_STORAGE}"
~~~
https://devdocs.magento.com/guides/v2.2/config-guide/varnish/tshoot-varnish-503.html
## 22,unable to send mail
magento2發不了郵件 `unable to send mail`。
見
//bbs.mallol.cn/?thread-186.htm
## 23,后臺可視化編輯器圖片上傳失敗`File validation failed`
這是2.2.5的一個bug。
需要安裝php fileinfo擴展
7.0版本這樣安裝:
~~~
sudo apt-get install php7.0-fileinfo
~~~
7.1版本這樣安裝:
~~~
sudo apt-get install php7.1-fileinfo
~~~
https://github.com/magento/magento2/issues/16531
## 24,后臺登錄不進去
登錄后臺報錯:
'You did not sign in correctly or your account is temporarily disabled'
這個是你后臺用戶賬號被鎖住了,需要解鎖,用下面這個命令:
~~~
php bin/magento admin:user:unlock admin
~~~
最后面的`admin`是你的登錄用戶名,自行修改即可。
如果上面的還不行的話,就再試下下面的辦法:
M2后臺登錄用戶名和密碼都是默認有有效期的。到期后 就登錄不了 提示要修改密碼。
也有可能是密碼不對。
1,先強制登錄(臨時修改下源碼)
Go to this file path and \\vendor\\zendframework\\zend-crypt\\src\\Utils.php and echo $expected and $actual variable and check both are same or not if both variable are not match then change line no 35
```
if (function\_exists('hash\_equals')) { return hash\_equals($expected, $actual); }
```
To
```
if (function\_exists('hash\_equals')) { return true; }
```
2,登陸進去后修改下Configuration
```
Configuration->ADVANCED->Admin->Security
```
`Admin Account Sharing` 設為 yes
`Admin Session Lifetime (seconds)` 設為最大值 31536000
`Password Lifetime (days)` 設為空
**保存后,再還原之前改的源代碼**
- 序言
- 全面解讀Magento2
- Magento2簡介
- Magento2特點
- Magento2目錄結構
- Magento2語法講解
- 運行原理剖析
- 開啟Magento2之旅
- 安裝Magnto2
- 購買阿里云服務器(Ubuntu系統)
- 安裝和配置Nginx/PHP/PHP-FPM
- 配置Mysql并創建數據庫
- 配置Nginx虛擬主機
- 安裝和配置Magento2
- 導入演示數據
- 手把手教你創建git代碼庫
- 續外篇-購買AWS服務器
- 續外篇-Mac下安裝LNMP
- 續外篇-安裝phpmyadmin
- 如何升級php版本
- 使用Magento2
- 創建多網店多域名以及安裝中文語言包
- 創建獨立cms頁面
- 創建分類和產品
- 創建產品屬性
- 創建優惠券
- 導入產品csv
- 下單/發票/發貨/退貨
- M2常用命令
- 如何安裝主題
- 如何安裝插件
- 如何使用API
- 常見問題
- 常見問題 二
- 常見問題 三
- 常見問題 四
- 常見問題 五
- Magento2主題
- 主題框架詳解
- Layout文件詳解
- M2里的JS
- 主題實戰
- 前期準備工作
- 完成首頁
- 重寫分類頁面
- 錦囊妙計
- 產品詳情頁面講解
- 購物車頁面講解
- 支付頁面講解
- 主題修改記錄
- 關于主題的一些學員問答
- Magento2插件
- 插件框架詳解
- XML配置說明
- 插件實戰
- 準備工作
- 寫代碼
- 調試
- 難點解析
- 插件升級
- 插件修改記錄
- 擴展閱讀
- 如何創建cron任務和功能
- 發送郵件(帶附件)
- 如何在代碼里創建屬性
- Magento2線上部署
- 基本流程
- 配置Redis
- 配置Varnish+SSL
- Varnish配置教程(2020年修訂版)
- Paypal設置
- 一些優化
- Magento2 版本升級
- v2.3.0版本填坑指南
- v2.4.x升級指南
- 配置nginx pagespeed模塊進行加速
- M1數據庫遷移到M2指南
- 安裝配置Elasticsearch
- Magento2常用工具
- 網站測速分析工具
- 在線創建插件模塊
- M2后臺可視化編輯器里的標簽變量
- 遇到問題,我該怎么做
- 常用代碼
- SEO在線分析工具
- 本地用xdebug遠程調試mgtdev2服務器的項目
- 后續之路