宝塔面板安装Magento 2.4.2-p1 详细教程

来自一位群友的分享,他因为忙没时间发表,就由我代劳。他发了一些资料给我整理。感谢这位群友的无私分享。

基本情况

  • 系统:CentOS-8.3.2011-x86_64-dvd1 6核 6G
  • 软件:宝塔面板(BT) + OneinStack

BT 用于上传文件 运行SSH

OneinStack 用于LNMP

 

已知变量

1,magento密钥(下面的是假设的,你改成你自己的)

Public Key: c6a9870140f0f7bd66ceffcbbc07xxxx
Private Key: 6a5f67fb6b2bf41928534fe6be8cxxxx

2,网站域名

shop.magentotest.com

 

步骤1-环境安装LNMP

BT安装

cd /root
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh

安装完成后,会显示相关的url和端口等信息。

更改端口 用户 密码

比如

http://192.168.88.123:55567/123abc
username: xxxx
password: xxxx

 

 

OneinStack 安装

下载 解压

cd /root
yum -y install wget screen
wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz
tar xzf oneinstack-full.tar.gz

准备 安装

cd oneinstack
cd /root/oneinstack
./install.sh

 

安装选项

ssh22开始

Enter 回车
n
y
1
n
5
y
1
ffed644e4f969bcf
1
y
9
y
1
4 6 11
y
y
y
n
漫长的等待

 

步骤2-添加虚拟主机

cd oneinstack
cd /root/oneinstack
./vhost.sh
1   3
shop.magentotest.com
Enter 回车
n
n
y
magento2
y

修改php.ini

vi 修改 /usr/local/php/etc/php.ini
和 /usr/local/php/etc/php.d/ext-*.ini

找到并修改下列的参数

  • memory_limit = 384M
  • memory_limit = 4G
  • opcache.memory_consumption=384
  • opcache.memory_consumption=4G
  • realpath_cache_size=10M
  • realpath_cache_ttl=7200
  • max_input_vars = 6000

 

php.ini要去掉的函数

  • putenv
  • proc_open
  • shell_exec
  • exec
  • proc_get_status

 

查看PHP已经安装扩展

php -m

 

修改/usr/local/php/etc/02-opcache.ini

;opcache.save_comments=0 取消注释
opcache.save_comments=1

 

相关命令

Nginx/Tengine/OpenResty:

service nginx {start|stop|status|restart|reload|configtest}

 

MySQL/MariaDB/Percona:

service mysqld {start|stop|restart|reload|status}

 

PHP:

service php-fpm {start|stop|restart|reload|status}

service php-fpm restart
service php-fpm stop
service php-fpm start

 

 

步骤3-安装Elasticsearch

安装Java软件开发套件(JDK)

cd /root
java -version

 

在CentOS上安装JDK

yum -y install java-1.8.0-openjdk

 

Magento2.4 安装elasticsearch7 BlizzardWu

1.下载安装

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.1-x86_64.rpm
sudo rpm --install elasticsearch-7.9.1-x86_64.rpm

视安装位置而定

cd /etc/elasiticsearch
cd /etc/elasticsearch

sudo chkconfig --add elasticsearch
sudo -i service elasticsearch start
sudo -i service elasticsearch stop
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
sudo systemctl stop elasticsearch.service
sudo systemctl start elasticsearch.service

2.打开9200 端口
3.测试下面地址:

curl -X GET "localhost:9200/?pretty"

4.输出结果

{
"name" : "iZ8vbe999w4lcg8sc7qm78Z",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "B3VcAesAR224khl43VRKpQ",
"version" : {
"number" : "7.9.1",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "083627f112ba94dffc1232e8b42b73492789ef91",
"build_date" : "2020-09-01T21:22:21.964974Z",
"build_snapshot" : false,
"lucene_version" : "8.6.2",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}

 

5,通用检验是否安装成功:

curl 127.0.0.1:9200

 

成功返回如下:

{
"name" : "iZj6c5w0d1f4ltvrd3ukfrZ",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "9NRUr8r-QRSOZ_6b2Eli2w",
"version" : {
"number" : "7.9.1",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "083627f112ba94dffc1232e8b42b73492789ef91",
"build_date" : "2020-09-01T21:22:21.964974Z",
"build_snapshot" : false,
"lucene_version" : "8.6.2",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}

失败返回如下:

curl: (7) Failed connect to 127.0.0.1:9200; 拒绝连接

解决:

sudo sysctl -w vm.max_map_count=262144

成功的话可以忽视 继续安装

 

步骤4-安装配置Composer

omposer是一个PHP包管理和包依赖管理的工具。请按以下步骤安装配置Composer。

运行以下命令安装Composer。

curl -sS https://getcomposer.org/installer | php

运行以下命令配置Composer全局使用。

mv /root/composer.phar /usr/bin/composer

运行命令composer -v查看Composer版本。
返回结果如下,表示Composer安装成功。
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.8.5 2019-04-09 17:46:47

 

步骤5-安装Magento2.4

切换用户
su root
密码
或关闭重开ssh 有需要的话

cd /data/wwwroot/shop.magentotest.com
ll

 

OneinStack目录

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /data/wwwroot/shop.magentotest.com

BT目录

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /www/wwwroot/shop.magentotest.com

 

等待下载完

cd /www/wwwroot/shop.magentotest.com
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-data . # Ubuntu
chmod u+x bin/magento

有了宝塔这里就不用了 直接改权限

期待没有报错 一直走完

bin/magento setup:install \
--base-url=http://shop.magentotest.com \
--db-host=localhost \
--db-name=magento \
--db-user=root \
--db-password=ffed644e4f969bcf \
--admin-firstname=M \
--admin-lastname=eCBAY \
[email protected] \
--admin-user=admecbay \
--admin-password=mecbay555 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1 \
--search-engine=elasticsearch7 \
--elasticsearch-host=localhost \
--elasticsearch-port=9200

 

 

 

一切只为这一刻 还不错

设置后台管理路径
php bin/magento setup:config:set --backend-frontname="admec"

装完了看首页 再改权限

OneinStack目录

chmod -R 777 /data/wwwroot/shop.magentotest.com/*
chown -R www.www /data/wwwroot/shop.magentotest.com

BT目录

chmod -R 777 /www/wwwroot/shop.magentotest.com/*
chown -R www.www /www/wwwroot/shop.magentotest.com

 

常用命令

更新(如有安装新模块可以运行)
php bin/magento setup:upgrade

部署静态视图文件
php bin/magento setup:static-content:deploy -f

清除缓存
php bin/magento cache:clean

刷新缓存
php bin/magento cache:flush

刷新全部索引
php bin/magento indexer:reindex
————————————————

 

后台登录报 TwoFactorAuth,解决办法:

bin/magento module:disable Magento_TwoFactorAuth

 

 

步骤6-POERTO模板安装

上传模板 快速安装包等 解压覆盖
1 Theme Files 上传解压缩

2 Activate SW Extensions, open command line in folder root of magento and run commands via ssh using putty or others, php bin/magento setup:upgrade.

Module 'Mageplaza_Core' from '/data/wwwroot/shop.magentotest.com/app/code/Mageplaza/Core' has been already defined in '/data/wwwroot/www.123abc.com/vendor/mageplaza/module-core'

Solution
Step 1: You should DELETE Core module from

app/code/Mageplaza/Core
vendor/mageplaza/core-m2 (if any)
Run the following command:

composer remove mageplaza/module-core
rm -rf app/code/Mageplaza/Core
rm -rf vendor/mageplaza/module-core
composer dump-autoload

Step 2: Now install Mageplaza_Core again run upgrade command line to resolve the issue.

composer require mageplaza/module-core
php bin/magento setup:upgrade

Step 3: Check result

Check the result, if there is still an issue, feel free to leave a comment here or contact us

 

步骤6-语言包安装

 

美国、英国、中文、德语、法语、西班牙、意大利、日本
CN cn 0 CN Website Store cn_website_store CN Store View cn_store_view CN Category 2
DE de 1 DE Website Store de_website_store DE Store View de_store_view DE Category 3
ES es 2 ES Website Store es_website_store ES Store View es_store_view ES Category 4
FR fr 3 FR Website Store fr_website_store FR Store View fr_store_view FR Category 5
IT it 4 IT Website Store it_website_store IT Store View it_store_view IT Category 6
UK uk 5 UK Website Store uk_website_store UK Store View uk_store_view UK Category 7
US us 6 US Website Store us_website_store US Store View us_store_view US Category 8
XX xx 7 XX Website Store xx_website_store XX Store View xx_store_view XX Category 9

中文: https://github.com/mageplaza/magento-2-chinese-language-pack zh_Hans_CN CN
composer require mageplaza/magento-2-chinese-language-pack:dev-master

德语: https://github.com/mageplaza/magento-2-german-language-pack de_DE DE
composer require mageplaza/magento-2-german-language-pack:dev-master

西班牙: https://github.com/mageplaza/magento-2-spanish-language-pack es_ES ES
composer require mageplaza/magento-2-spanish-language-pack:dev-master

法语: https://github.com/mageplaza/magento-2-french-language-pack fr_FR FR
composer require mageplaza/magento-2-french-language-pack:dev-master

意大利: https://github.com/mageplaza/magento-2-italian-language-pack it_IT IT
composer require mageplaza/magento-2-italian-language-pack:dev-master

英语 https://github.com/mageplaza/magento-2-english-united-kingdom-language-pack en_GB UK
composer require mageplaza/magento-2-english-united-kingdom-language-pack:dev-master

英文: 自带英文 en-US US

 

 

安装中文语言包

Install Chinese pack:
composer require mageplaza/magento-2-chinese-language-pack:dev-master
php bin/magento setup:static-content:deploy zh_Hans_CN XXX
《php bin/magento setup:static-content:deploy -f en_US zh_Hans_CN》
《php bin/magento setup:static-content:deploy en_US en_GB de_DE fr_FR es_ES it_IT zh_Hans_CN -f》
php bin/magento setup:static-content:deploy zh_Hans_CN -f
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento cron:run

Update Chinese pack:

composer update mageplaza/magento-2-chinese-language-pack:dev-master
php bin/magento setup:static-content:deploy zh_Hans_CN -f
php bin/magento indexer:reindex
php bin/magento cache:clean
php bin/magento cache:flush

 

 

步骤7,一些注意事项

宝塔面板 注意用伪静态 把Oneinstack中的拿过来 全拿过来

server
{
    listen 80;
    server_name shop.jadebay.vip;
    set $MAGE_ROOT /www/wwwroot/shop.magentotest.com;
    root $MAGE_ROOT/pub;
    index index.php;
    autoindex off;
    charset UTF-8;
    error_page 404 403 /errors/404.php;
    #add_header "X-UA-Compatible" "IE=Edge";
放入网站配置文件中 注意改路径

以下全是伪静态放入伪静态保持为模板
  # PHP entry point for setup application
  location ~* ^/setup($|/) {

 

宝塔nginx配置文件

server
{
    listen 80;
    server_name shop.magentotest.com;
    set $MAGE_ROOT /www/wwwroot/shop.magentotest.com;
    root $MAGE_ROOT/pub;
    index index.php;
    autoindex off;
    charset UTF-8;
    error_page 404 403 /errors/404.php;
    #add_header "X-UA-Compatible" "IE=Edge";
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #SSL-END
    
    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP引用配置,可以注释或修改
    include enable-php-74.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/shop.magentotest.com.conf;
    #REWRITE-END
    
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log /dev/null;
        access_log /dev/null;
    }
    
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log /dev/null;
        access_log /dev/null; 
    }
    access_log  /www/wwwlogs/shop.magentotest.com.log;
    error_log  /www/wwwlogs/shop.magentotest.com.error.log;
}

 

宝塔伪静态文件

# PHP entry point for setup application
location ~* ^/setup($|/) {
  root $MAGE_ROOT;
  location ~ ^/setup/index.php {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }

  location ~ ^/setup/(?!pub/). {
    deny all;
  }

  location ~ ^/setup/pub/ {
    add_header X-Frame-Options "SAMEORIGIN";
  }
}

# PHP entry point for update application
location ~* ^/update($|/) {
  root $MAGE_ROOT;
  location ~ ^/update/index.php {
    fastcgi_split_path_info ^(/update/index.php)(/.+)$;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    include fastcgi_params;
  }

  # Deny everything but index.php
  location ~ ^/update/(?!pub/). {
    deny all;
  }

  location ~ ^/update/pub/ {
    add_header X-Frame-Options "SAMEORIGIN";
  }
}

location / {
  try_files $uri $uri/ /index.php?$args;
}

location /pub/ {
  location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
    deny all;
  }
  alias $MAGE_ROOT/pub/;
  add_header X-Frame-Options "SAMEORIGIN";
}

location /static/ {
  # Uncomment the following line in production mode
  # expires max;
  # Remove signature of the static files that is used to overcome the browser cache
  location ~ ^/static/version {
    rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
  }

  location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
    add_header Cache-Control "public";
    add_header X-Frame-Options "SAMEORIGIN";
    expires +1y;
    if (!-f $request_filename) {
        rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
    }
  }

  location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
    add_header Cache-Control "no-store";
    add_header X-Frame-Options "SAMEORIGIN";
    expires off;
    if (!-f $request_filename) {
      rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
    }
  }

  if (!-f $request_filename) {
    rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
  }
  add_header X-Frame-Options "SAMEORIGIN";
}

location /media/ {
  try_files $uri $uri/ /get.php?$args;
  location ~ ^/media/theme_customization/.*\.xml {
    deny all;
  }

  location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
    add_header Cache-Control "public";
    add_header X-Frame-Options "SAMEORIGIN";
    expires +1y;
    try_files $uri $uri/ /get.php?$args;
  }
  location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
    add_header Cache-Control "no-store";
    add_header X-Frame-Options "SAMEORIGIN";
    expires off;
    try_files $uri $uri/ /get.php?$args;
  }
  add_header X-Frame-Options "SAMEORIGIN";
}

location /media/customer/ {
  deny all;
}

location /media/downloadable/ {
  deny all;
}

location /media/import/ {
  deny all;
}

# PHP entry point for main application
location ~ (index|get|static|report|404|503)\.php$ {
  try_files $uri =404;
  fastcgi_pass unix:/dev/shm/php-cgi.sock;
  fastcgi_buffers 1024 4k;

  fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
  fastcgi_param PHP_VALUE "memory_limit=768M \n max_execution_time=600";
  fastcgi_read_timeout 600s;
  fastcgi_connect_timeout 600s;

  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
}

gzip on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
  text/plain
  text/css
  text/js
  text/xml
  text/javascript
  application/javascript
  application/x-javascript
  application/json
  application/xml
  application/xml+rss
  image/svg+xml;
gzip_vary on;

# Banned locations (only reached if the earlier PHP entry point regexes don't match)
location ~* (\.php$|\.htaccess$|\.git) {
  deny all;
}

 

发表评论