这是我接触magento2开发的记录,遇到的问题,都抽时间记录下来吧,做为我成长的见证

一、后台无法显示登录,提示《后台重定向次数过多》,查看nginx日志,提示如下:

解决方案:修改数据库表core_config_data,将web/cookie/cookie_domain修改为本机开发的域名,执行php bin/magento cache:clean

二、2.3.4版本加入购物车出现500错误,nginx日志如下:

2020/07/07 11:41:05 [error] 1189#1189: *3221 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function Magento\InventorySales\Model\IsProductSalableForRequestedQtyCondition\bccomp() in /var/www/html/m2.34-sg/vendor/magento/module-inventory-sales/Model/IsProductSalableForRequestedQtyCondition/IsSalableWithReservationsCondition.php:93
Stack trace:
#0 /var/www/html/m2.34-sg/vendor/magento/module-inventory-sales/Model/IsProductSalableForRequestedQtyCondition/IsProductSalableForRequestedQtyConditionChain.php(222): Magento\InventorySales\Model\IsProductSalableForRequestedQtyCondition\IsSalableWithReservationsCondition->execute('O-I3T-BK#-SG', 1, 1)
#1 /var/www/html/m2.34-sg/vendor/magento/module-inventory-sales/Model/IsProductSalableForRequestedQtyCondition/IsProductSalableForRequestedQtyConditionChain.php(162): Magento\InventorySales\Model\IsProductSalableForRequestedQtyCondition\IsProductSalableForRequestedQtyConditionChain->processSufficientConditions('O-I3T-BK#-SG', 1, 1)
#2 /var/www/html/m2.34-sg/vendor/magento/module-inventory-sales/" while reading response header from upstream, client: 127.0.0.1, server: sg.olight.com, request: "POST /checkout/cart/add/uenc/aHR0cDovL3NnLm9saWdodC5jb20vaTN0LWVvcy5odG1s/product/1566/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "sg.olight.com", referrer: "http://sg.olight.com/i3t-eos.html"

解决方案:安装php7.2-bcmath扩展

三、执行php bin/magento setup:upgrade升级命令时,报了以下的错误

Can't run this operation: deployment configuration is absent. Run 'magento setup:config:set --help' for options.

原因:配置文件未增加,

解决方案:参见官方或项目其它人员的配置,将/config.php、
env.php两个文件配置好本机的,复制到网站根目录app/etc下,再执行setup:upgrade就好

四、php bin/magento setup:upgrade升级时,出现以下异常,导致无法本机部署环境

Upgrading data.. SQLSTATE[HY000]: General error: 1449 The user specified as a definer ('admin'@'%') does not exist, query was: DELETE FROM `amasty_feed_entity` WHERE (entity_id='1')

原因:Triggers权限有问题,数据库是从其它地方导过来的,用户可能不一样,此表的Triggers里面Definer设置的用户,不存在我的数据库里面,所以要么增加指定用户的权限,要么修改Triggers的Definer值为有权限的用户

https://gurdeep.ninja/magento-2-user-specified-definer-not-exist/

https://dev.mysql.com/doc/refman/5.7/en/show-grants.html

解决方案:参见以下连接https://magento.stackexchange.com/questions/282262/magento-2-we-cant-place-the-order-sqlstatehy000-general-error-1449-the-u,将Definer的值改为root@localhost用户,最后重新setup:upgrade

五、增加秒杀产品清理缓存索引后,前台页面访问不了,报以下错误

1 exception(s):
Exception #0 (Exception): Item (LitExtension\Core\Model\Preference\Product\Product\Interceptor) with the same ID "1658" already exists.

解决方案:到数据库找到产品,删除后,重新索引(注:本机开发环境删除产品无所谓,如果是线上的话,自行看看有没有其它解决方案,实在不行,删除再重新添加看看了)

delete FROM `catalog_product_entity` where entity_id=1658

#完成后,到站点根目录,执行重新索引命令
php bin/magento indexer:reindex

参考:https://community.magento.com/t5/Magento-2-x-Technical-Issues/On-all-frontend-categories-Interceptor-with-the-same-ID-already/td-p/69642

六、执行bin/magento时报了commands defined错误,站点显示Please upgrade your database: Run "bin/magento setup:upgrade"

> php bin/magento setup:upgrade
                                                    
  There are no commands defined in the "setup" namespace.  
                                                           
命令行报错
Exception #0 (Magento\Framework\Exception\LocalizedException): Please upgrade your database: Run "bin/magento setup:upgrade" from the Magento root directory.
浏览器显示以上错误

原因:启用模块后,未先执行setup命令,就访问了站点,

解决方案:清理站点根目录下的var、generated、pub目录后,再重新安装

sudo chmod -R 0777 var/ pub/ generated/
rm -rf var/cache/* var/view_preprocessed/* generated/* pub/static/*
php bin/magento setup:upgrade
php bin/magento setup:di:compile

七、提示命令未定义

There are no commands defined in the "deploy:mode" namespace.

解决方案:给予指定目录权限,再执行命令即可

sudo chmod -R 0777 var/ pub/ generated/

八、访问站点出现以下报错

ReflectionException: Class Magento\Framework\App\Http\Interceptor does not exist in /var/www/html/m2.34-de/vendor/magento/framework/Code/Reader/ClassReader.php:26 Stack trace: #0 /var/www/html/m2.34-de/vendor/magento/framework/Code/Reader/ClassReader.php(26): ReflectionClass->__construct('Magento\\Framewo...') #1 /var/www/html/m2.34-de/vendor/magento/framework/ObjectManager/Definition/Runtime.php(54): Magento\Framework\Code\Reader\ClassReader->getConstructor('Magento\\Framewo...') #2 /var/www/html/m2.34-de/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(48): Magento\Framework\ObjectManager\Definition\Runtime->getParameters('Magento\\Framewo...') #3 /var/www/html/m2.34-de/vendor/magento/framework/ObjectManager/ObjectManager.php(56): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Magento\\Framewo...', Array) #4 /var/www/html/m2.34-de/vendor/magento/framework/App/Bootstrap.php(235): Magento\Framework\ObjectManager\ObjectManager->create('Magento\\Framewo...', Array) #5 /var/www/html/m2.34-de/pub/index.php(39): Magento\Framework\App\Bootstrap->createApplication('Magento\\Framewo...') #6 {main}

原因:应该是编译未完成就访问了,

解决方案:等编译命令执行完成先,不行就尝试以下命令再次编译

php bin/magento setup:di:compilephp
bin/magento setup:static-content:deploy -f

九、访问站点出现以下错误

1 exception(s):
Exception #0 (Magento\Framework\Exception\FileSystemException): Directory "/var/www/html/m2.34-de/pub/static/frontend/Olight/default/de_DE" cannot be created Warning!mkdir(): Permission denied

Exception #0 (Magento\Framework\Exception\FileSystemException): Directory "/var/www/html/m2.34-de/pub/static/frontend/Olight/default/de_DE" cannot be created Warning!mkdir(): Permission denied
<pre>#1 Magento\Framework\Filesystem\Driver\File->createDirectory() called at 

原因:静态目录未有权限,

解决方案:执行以下命令给予权限即可

sudo chmod -R 0777 var/ pub/ generated/

线上环境建议按官方配置:

sudo chown -R :www-data .
sudo find . -type d -exec chmod 770 {} + && sudo find . -type f -exec chmod 660 {} + && sudo chmod u+x bin/magento

官方参见:https://devdocs.magento.com/guides/v2.3/install-gde/install/legacy-file-system-perms.html

十、后台配置页面报以下错误

1 exception(s):
Exception #0 (Exception): Notice: Undefined index: id in /var/www/html/m2.34-sg/vendor/magento/module-config/Model/Config/Structure/Element/Iterator.php on line 63

Exception #0 (Exception): Notice: Undefined index: id in /var/www/html/m2.34-sg/vendor/magento/module-config/Model/Config/Structure/Element/Iterator.php on line 63
<pre>#1 Magento\Config\Model\Config\Structure\Element\Iterator->setElements() ca

原因:system.xml配置的tab实体不存在,没办法找到节点

解决方案:修改system.xml修改tab里面的值,设置为magento现有的节点就好

我的是安装mspDevTools开发辅助模块时,出现的问题,对比系统的tab后,修改app/code/MSP/DevTools/etc/adminhtml/system.xml下tab值msp_common改为advanced

            <!-- <tab>msp_common</tab> -->
            <tab>advanced</tab>

完成后,执行以下命令

php bin/magento cache:clean
php bin/magento setup:upgrade
chmod -R 0777 var/ pub/ generated/

十一、执行php bin/magento setup:upgrade时,出现以下错误

Deprecated Functionality: The each() function is deprecated.

原因:用了php7.2的版本跑了magento2.2的版本,

解决方案:切换到php7.1就好