Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

Magento2 安装系列五 使用命令安装magento2.4.6

前言

magento2自从2.4版本后,增加很多的功能,这也导致安装时出现的bug越来越多,这些bug基本都是因为2.4版本自带的扩展更新或者替换需要php扩展支持或者需要使用被php默认禁用的函数所导致的。

安装前需要准备的步骤

开始搭建环境

一、如果有服务器最好,没有就安装虚拟机,安装linux系统,参考安装系列一

二、安装宝塔,搭建php环境,参考安装系列二。注意:此篇文章是2020年写的,现在2023年了,大致的流程基本不变,变化的具体是版本的更新,下面是具体要更改的地方:

1.宝塔安装具体以官网为准,安装最新版本的 https://www.bt.cn/new/download.html

2.php环境安装需要8.1以上的版本

3.在php管理里安装这四个扩展

4.在php禁用函数里,开放以下函数

exec、putenv、shell_exec、proc_open、openlog、syslog

三、安装magento2.4.6需要的支持功能Elasticsearch

1.检查是否Elasticsearch已安装:

举例:

sudo systemctl status elasticsearch

//or

curl -X GET 'http://localhost:9200'

//or

curl -X GET 'http://yourdomaine:9200'

2.如果发现Elasticsearch已安装,则直接安装magento2.4

3.Elasticsearch安装:参考

3.1 我们必须有 OpenJDK 才能使 Elasticsearch 工作

sudo apt install openjdk-11-jdk -y

3.2 导入Elasticsearch GPG公钥

curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

3.3 将Elasticsearch源添加到sources.list.d目录中,apt将在其中搜索新源

sudo echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

3.4 更新包以读取Elastic源

sudo apt update

3.5 安装Elasticsearch

sudo apt install elasticsearch -y

3.6 我们配置Elasticsearch主机

sudo nano /etc/elasticsearch/elasticsearch.yml

取消注释并替换#network.host: 192.168.0.1network.host: localhost

# ---------------------------------- Network -----------------------------------
 #
 # Set the bind address to a specific IP (IPv4 or IPv6):
 #
 #network.host: 192.168.0.1 //<- **** uncomment this line then replace it with : network.host: localhost
 #
 # Set a custom port for HTTP:
 #
 #http.port: 9200
 #
 # For more information, consult the network module documentation.

nano保存并退出

要保存对文件所做的更改,请按Ctrl+O。如果该文件尚不存在,则在保存后将创建该文件。

退出 Ctrl+X。如果有未保存的更改,系统会询问您是否要保存更改。

要保存文件,您必须具有该文件的写入权限。如果要创建新文件 ,则需要对创建该文件的目录具有写权限

3.7 我们启动Elasticsearch

 sudo systemctl start elasticsearch
 sudo systemctl enable elasticsearch

3.8 检查状态

 sudo systemctl status elasticsearch

 //result : 

 //systemd[1]: Starting Elasticsearch...

3.9 Working Elastic

 curl -X GET 'localhost:9200' 

 //Result something like : 
 {
   "name" : "wbfdfrbz",
   "cluster_name" : "elasticsearch",
   "cluster_uuid" : "_MpzR9k23l-Vy5vzlSQW",
   "version" : {
     "number" : "7.9.0",
     "build_flavor" : "default",
     "build_type" : "deb",
     "build_hash" : "a179a2a7fwq032d6g9361301700902wff217",
     "build_date" : "2020-08-11T21:36:48.204330Z",
     "build_snapshot" : false,
     "lucene_version" : "8.6.0",
     "minimum_wire_compatibility_version" : "6.8.0",
     "minimum_index_compatibility_version" : "6.0.0-beta1"
   },
  "tagline" : "You Know, for Search"
 }

至此,Elasticsearch安装成功

四、开始安装magento2.4.6

在步骤 中3.6,我们使用localhost ( ) 设置HOST值,因此我们将为和进行相同的设置,我们保留默认端口9200 ( )。network.host: localhost--elasticsearch-host='localhost'--elasticsearch-port=9200#http.port: 9200

Magento CLI 安装的示例:

php bin/magento setup:install --base-url="http://yourdomaine.com/" --base-url-secure="http://yourdomaine.com/" --backend-frontname="admin" --session-save="files" --db-host="localhost" --db-name="your-db-name" --db-user="your-db-user" --db-password="your-db-password" --admin-firstname="Amir" --admin-lastname="Admin" --admin-email="amir@domaine.com" --admin-user="amir" --admin-password="Admin123" --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 --search-engine=elasticsearch7 --elasticsearch-host="localhost" --elasticsearch-port=9200

将命令中的参数替换为您的实际值:

  • <your-base-url>: 您的网站的基本 URL。
  • <your-db-host>: 数据库主机名。
  • <your-db-name>: 数据库名称。
  • <your-db-username>: 数据库用户名。
  • <your-db-password>: 数据库密码。
  • <your-admin-firstname>: 管理员的名字。
  • <your-admin-lastname>: 管理员的姓氏。
  • <your-admin-email>: 管理员的电子邮件地址。
  • <your-admin-username>: 管理员的用户名。
  • <your-admin-password>: 管理员的密码。
  • <your-language>: 您希望使用的语言(例如:en_US)。
  • <your-currency>: 您希望使用的货币代码(例如:USD)。
  • <your-timezone>: 您希望使用的时区(例如:America/New_York)。

请确保提供正确的参数值,并根据您的需求进行调整

五、运行magento命令

先切换到www权限,sudo su -s /bin/bash www 。再运行magento命令

rm -rf generated
rm -rf pub/static/adminhtml
rm -rf pub/static/frontend
rm -rf var/view_preprocessed
php -dmemory_limit=2G bin/magento setup:upgrade
php -dmemory_limit=2G bin/magento setup:di:compile
php -d memory_limit=2G bin/magento indexer:reset
php -d memory_limit=2G bin/magento indexer:reindex
php -d memory_limit=2G bin/magento setup:static-content:deploy -f en_US
php bin/magento cache:clean
php bin/magento cache:flush
chmod -R 777 pub
chmod -R 777 var
chmod -R 777 generated
chmod -R 777 app/etc

如果运行命令没有任何报错,顺利跑完,那么,恭喜你,magento2.4.6安装成功!!!

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论