基于宝塔环境安装magento2系统:
数据库只能大于等于Mysql5.7+服务选择:Nginx1.18 或者 apache2.4
先设置php的内存大小:尽量调整的大一点如图所示
![](https://img.kancloud.cn/2c/93/2c930d9ae2c529f7be5fe74bc0377aad_652x603.png)
然后执行下一步,安装JDK环境,步骤如下:
下载jdk:(直接复制我的路径黏贴与ssh中执行即可)
wget --no-cookies --no-check-certificate --header "Cookie: gpw\_e24=http:%2F%[2Fwww.oracle.com%2F;](http://2fwww.oracle.com%2f%3b/) oraclelicense=accept-securebackup-cookie" "[https://download.oracle.com/otn-pub/java/jdk/16+36/7863447f0ab643c585b9bdebf67c69db/jdk-16\_linux-x64\_bin.rpm](https://download.oracle.com/otn-pub/java/jdk/16+36/7863447f0ab643c585b9bdebf67c69db/jdk-16_linux-x64_bin.rpm)"
安装JDK:
sudo rpm -ivh jdk-16\_linux-x64\_bin.rpm
待安装完JDK环境后,执行安装[elasticsearch](https://artifacts.elastic.co/downloads/elasticsearch/e) 服务,简称ES:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch\-7.12.0\-x86\_64.rpm
此过程根据服务器的带宽以及所处地域决定快慢,如果是国内服务器需要等待较长时间
待下载完成后执行安装ES操作:
sudo rpm \--install elasticsearch\-7.12.0\-x86\_64.rpm
待安装完毕后执行启动ES服务命令:
systemctl start elasticsearch.service
执行此步骤如果不出现结果就是正常情况,
然后查看ES运行状态:
service elasticsearch status
执行以上命令出现下列情况就是正常:
![](https://img.kancloud.cn/d5/82/d582afbf0a63f67e74b4cb535f806beb_665x421.png)
然后切换到站点根目录:
cd /www/wwwroot/域名
然后执行创建数据库语句:
bin/magento setup:install \\
\--base-url=[http:](http://yz.woeru.com/)//[niubeing.com](http://niubeing.com/)/ \\
\--db-host=localhost \\
\--db-name=niubeing\_com \\
\--db-user=niubeing\_com\\
\--db-password=AGw6HGMkSNiZ3HJwA1S2D3G5H6J7\\
\--admin-firstname=admin \\
\--admin-lastname=admin \\
\--admin-email=[admin@admin.com](mailto:admin@admin.com) \\
\--admin-user=admin \\
\--admin-password=admin888 \\
\--language=en\_US \\
\--currency=USD \\
\--timezone=America/Chicago \\
\--use-rewrites=1 \\
\--search-engine="elasticsearch7" \\
\--elasticsearch-host="127.0.0.1" \\
\--elasticsearch-port="9200"
安装完上述操作之后记得去站点的文件里面添加如下代码:
upstream fastcgi\_backend {
server unix:/tmp/php-cgi-73.sock;
}
set $MAGE\_ROOT /www/wwwroot/shop.uniapp.vip;
include /www/wwwroot/shop.uniapp.vip/nginx.conf.sample;
# root /www/wwwroot/shop.uniapp.vip;
常见问题:
如果安装之后首页空白,则需要执行:
cd 站点的路径
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R[www.www](http://www.www/)
chmod u+x bin/magento
sudo chmod 777 -R var
# magento2.4遇到的错误记录:
错误:You need to configure Two-Factor Authorization in order to proceed to your store’s admin area
bin/magento module:disable Magento\_TwoFactorAuth
bin/magento cache:flush
![](https://img.kancloud.cn/95/07/9507a9c864f96a4cca45f462fc41f4c8_785x723.png)
如果忘了magento2的后台登录地址,则查看:/www/wwwroot/shop.uniapp.vip/app/etc/env.php 文件里面的 frontName 的值,这个后台的地址可以自己随意修改
![](https://img.kancloud.cn/7f/a7/7fa71ed88338787fa5e317b7fde7cff3_995x389.png)
复位magento基本配置,开启前后台https
php bin/magento config:set web/cookie/cookie\_domain NULL
php bin/magento config:set web/unsecure/base\_url [http://www.yoursite.com/](http://www.yoursite.com/)
php bin/magento config:set web/secure/base\_url [https://www.yoursite.com/](https://www.yoursite.com/)
php bin/magento config:set web/secure/use\_in\_frontend 1
php bin/magento config:set web/secure/use\_in\_adminhtml 1
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex
php bin/magento cache:clean