magento2开发中常见问题

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
那你deployN遍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是你的登录用户名,自行修改即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值