サンプルデータを使用するため、あえてMagento2.3.5をインストールする

我开始学习Magento,但似乎安装方法在Magento2.3和Magento2.4之间有所变化(我想要检查样本数据,但在2.4上没有成功)。所以我打算安装稍微旧一点的Magento2.3.5版本。我将根据官方的2.3系安装指南进行操作。

准备工作

必须的软件

image.png

除了Magento之外,还需要以下内容(来源:Adobe Version 2.3文档)。

    • Composer(1)

 

    • Elasticsearch(7.6)

 

    • MySQL(5.6, 5.7)

 

    • PHP(7.2, 7.3)

 

    Apache(2.4)

服务器准备工作

由于手里没有合适的Linux服务器,所以在Google Cloud上进行了搭建。考虑到在使用Composer部署时会消耗大量内存,因此采用了以下配置。

image.png

请给予您的承诺

sudo apt update; sudo apt upgrade

我会去做的。 (Wǒ huì qù zuò de.)

Apache -> 阿帕奇

sudo apt install apache2
image.png

/etc/apache2/sites-available/000-default.confの更新

需要添加红框中的部分。如果不进行此设置,Magento2将无法运行。

image.png
        <Directory /var/www/html>
                AllowOverride All
                Require all granted
        </Directory>

重新启用

为了运行Magento2,请进行以下设置……启用mod_rewrite。

~$ sudo a2enmod
Your choices are: access_compat actions alias allowmethods asis auth_basic auth_digest auth_form authn_anon authn_core authn_dbd authn_dbm authn_file authn_socache authnz_fcgi authnz_ldap authz_core authz_dbd authz_dbm authz_groupfile authz_host authz_owner authz_user autoindex buffer cache cache_disk cache_socache cern_meta cgi cgid charset_lite data dav dav_fs dav_lock dbd deflate dialup dir dump_io echo env expires ext_filter file_cache filter headers heartbeat heartmonitor http2 ident imagemap include info lbmethod_bybusyness lbmethod_byrequests lbmethod_bytraffic lbmethod_heartbeat ldap log_debug log_forensic lua macro mime mime_magic mpm_event mpm_prefork mpm_worker negotiation php8.1 proxy proxy_ajp proxy_balancer proxy_connect proxy_express proxy_fcgi proxy_fdpass proxy_ftp proxy_hcheck proxy_html proxy_http proxy_http2 proxy_scgi proxy_wstunnel ratelimit reflector remoteip reqtimeout request rewrite sed session session_cookie session_crypto session_dbd setenvif slotmem_plain slotmem_shm socache_dbm socache_memcache socache_shmcb speling ssl status substitute suexec unique_id userdir usertrack vhost_alias xml2enc
Which module(s) do you want to enable (wildcards ok)?
rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
  systemctl restart apache2

我会重新启动Apache。

sudo systemctl restart apache2

MySQL是一种开源的关系型数据库管理系统。

バージョンをきちんと指定してインストールしたいので、UbuntuでMySQL 5.7をインストールする方法を参照して作業を進めます。

$ wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
$ sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
image.png

添加APT密钥。

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29

我会执行sudo apt update命令。

$ sudo apt update

我会确认是否添加了存储库。

$ sudo apt-cache policy mysql-server
mysql-server:
  Installed: (none)
  Candidate: 5.7.40-1ubuntu18.04
  Version table:
     5.7.40-1ubuntu18.04 500
        500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages
     5.7.40-0ubuntu0.18.04.1 500
        500 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
     5.7.21-1ubuntu1 500
        500 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

将进行5.7的安装。在此过程中,会要求输入Root密码。

$ sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*
image.png

如果安装成功,我会尝试从命令行登录来确认一下。

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

MySQL数据库配置以及其他设置

前の章から引き継ぎ、MySQLのなかでmagent2というデータベースを作成します。

CREATE DATABASE magento2;

magentipというユーザを作成します。ここでmagentipのパスワードも設定します。

CREATE USER 'magentip'@'localhost' IDENTIFIED BY '<your_pssword>';
ALTER USER 'magentip'@'localhost' IDENTIFIED WITH mysql_native_password BY '<your_pssword>';

magentipに権限付与します。

GRANT ALL PRIVILEGES ON *.* TO 'magentip'@'localhost' WITH GRANT OPTION;

由于更改了权限,请在退出控制台之前执行FLUSH PRIVILEGES命令。

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye

PHP是一种广泛使用的服务器脚本语言,用于开发动态网站。

Magento2.3.5所需的PHP版本为7.2和7.3。您可以通过apt install命令安装来确认可安装的PHP版本。

$ sudo apt-cache policy php
php:
  Installed: (none)
  Candidate: 1:7.2+60ubuntu1
  Version table:
     1:7.2+60ubuntu1 500
        500 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

因此,直接安装它。

$ sudo apt install php
(途中略)
 php -v
PHP 7.2.24-0ubuntu0.18.04.15 (cli) (built: Nov  2 2022 09:09:52) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24-0ubuntu0.18.04.15, Copyright (c) 1999-2018, by Zend Technologies

已经安装了7.2版本。

安装所需的模块。

sudo apt install php7.2-bcmath php7.2-intl php7.2-soap php7.2-zip php7.2-gd php7.2-curl php7.2-cli php7.2-xml php7.2-xmlrpc php7.2-gmp php7.2-common php7.2-mbstring php7.2-mysql

弹性搜索

事后我意识到,在2.3.5版本中是不需要的。

安装Java

首先安装Java(OpenJDK)。

请使用以下命令来确认您可以安装的OpenJDK版本。

$ sudo apt search "^openjdk.*jdk$"
Sorting... Done
Full Text Search... Done
openjdk-11-jdk/bionic-updates,bionic-security 11.0.17+8-1ubuntu2~18.04 amd64
  OpenJDK Development Kit (JDK)

openjdk-17-jdk/bionic-updates,bionic-security 17.0.5+8-2ubuntu1~18.04 amd64
  OpenJDK Development Kit (JDK)

openjdk-8-jdk/bionic-updates,bionic-security 8u352-ga-1~18.04 amd64
  OpenJDK Development Kit (JDK)

可以安装OpenJDK-17-JDK。

sudo apt update
sudo apt-get install openjdk-17-jdk

Javaのバージョンを確認します。

$ java -version
openjdk version "17.0.5" 2022-10-18
OpenJDK Runtime Environment (build 17.0.5+8-Ubuntu-2ubuntu118.04)
OpenJDK 64-Bit Server VM (build 17.0.5+8-Ubuntu-2ubuntu118.04, mixed mode, sharing)

Elasticsearchのインストール

Elasticsearchのインストールを開始します。

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

Elastic-7.x.listをsource.list.dに加えます(そういう意味らしい)。

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

Elasticsearchの本体をインストールします。

sudo apt update
sudo apt install elasticsearch

将Elasticsearch注册为服务。

$ sudo systemctl daemon-reload
$ sudo systemctl enable elasticsearch.service
Synchronizing state of elasticsearch.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable elasticsearch
Created symlink /etc/systemd/system/multi-user.target.wants/elasticsearch.service → /usr/lib/systemd/system/elasticsearch.service.

Elasticsearch的设置

以下ファイルの設定を行います(この辺りはこちらのサイトより引用)。

    • elasticsearch.yml

 

    elasticsearch.service

elasticsearch配置文件

sudo vi /etc/elasticsearch/elasticsearch.yml

去掉cluster.name和node.name前面的#,将node.name更改为’My First Node’。

image.png
image.png

また、以下も変更します。

image.png

elasticsearch.service

sudo vi /usr/lib/systemd/system/elasticsearch.service
image.png

ここまでの設定が終わったらelasticserchサービスを開始します(コマンドプロンプトが返ってくるまで1~2分必要です)。

$ sudo systemctl daemon-reload
$ sudo systemctl start elasticsearch.service
$ sudo systemctl start elasticsearch.service

curlで http://localhost:9200 にアクセスして動作確認します。

$ curl -X GET 'http://localhost:9200'
{
  "name" : "My First Node",
  "cluster_name" : "my-application",
  "cluster_uuid" : "_na_",
  "version" : {
    "number" : "7.17.7",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "78dcaaa8cee33438b91eca7f5c7f56a70fec9e80",
    "build_date" : "2022-10-17T15:29:54.167373105Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

elasticsearchが動いていることを確認できました。

Magento = 马gento

使用Composer工具下载Magento软件。

安装composer

インストールに必要なファイルを取得します。

curl -sS https://getcomposer.org/installer -o composer-setup.php

当前目录的状态会变成这样。

~/tmp$ curl -sS https://getcomposer.org/installer -o composer-setup.php
:~/tmp$ ls
composer-setup.php

Magento 2.3.5ではcomposer 1が必要なのでオプション –1を付けます。

$ sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer --1
All settings correct for using Composer
Warning: You forced the install of Composer 1.x via --1, but Composer 2.x is the latest stable version. Updating to it via composer self-update --stable is recommended.
Downloading...

Composer (version 1.10.26) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

ちょっと怒られているけどインストール完了です。バージョンを確認します。

p$ composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.10.26 2022-04-13 16:39:56

Magento2.3.5 是一个选项。

Magento的访问密钥

因此,在之后需要Magento的Access Key,所以请提前获取(在Adobe的页面上有获取方法的说明)。获取到的Access Key可以用于…

-用户名:公共密钥
-密码:私有密钥

作为使用。

创建Magento用户

从这里开始,根据所引用的文章,内容会有所不同。从这里开始,我将参考这篇文章。

MagentoのCLI操作やCRON用のユーザを用意します(パスワードを聞かれるので用意しておいてください)。

$ sudo adduser magento_user
Adding user `magento_user' ...
Adding new group `magento_user' (1003) ...
Adding new user `magento_user' (1002) with group `magento_user' ...
Creating home directory `/home/magento_user' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for magento_user
Enter the new value, or press ENTER for the default
        Full Name []: Magento2 User
        Room Number []: 
        Work Phone []: 
        Home Phone []: 
        Other []: 
Is the information correct? [Y/n] Y

将默认组更改为www-data组。

sudo usermod -g www-data magento_user

我会将其加入到sudo用户组中。

sudo adduser magento_user sudo

下载Magento2.3.5。

我们将使用先前创建的magento_user来进行操作,因此会使用su命令进行切换。

su - magento_user

将DocumentRoot文件夹的所有者更改为magento_user。由于没有特别更改DocumentRoot,因此路径为/var/www/html。

$ sudo chown magento_user:www-data /var/www/html -R
$ ls -all
total 20
drwxr-xr-x 2 magento_user www-data  4096 Nov 14 06:40 .
drwxr-xr-x 3 root         root      4096 Nov 14 06:40 ..
-rw-r--r-- 1 magento_user www-data 10918 Nov 14 06:40 index.html

由于Magento 2是作为HTML内容进行安装的,所以需要更改当前目录为安装目录(通常是/var/www/html)。注意,如果目录中有内容,则在安装过程中会出现错误,因此需要删除原先存在的index.html文件。

$ cd /var/www/html
$ rm index.thml
$ $ ls -all
total 8
drwxr-xr-x 2 magento_user www-data 4096 Nov 14 08:13 .
drwxr-xr-x 3 root         root     4096 Nov 14 06:40 ..

ダウンロードを開始します。結構時間がかかります。

$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.3.5 .
Creating a "magento/project-community-edition=2.3.5" project at "./"
Installing magento/project-community-edition (2.3.5)
  - Installing magento/project-community-edition (2.3.5): Loading from cache
Created project in /var/www/html/.
Loading composer repositories with package information
Warning from https://repo.packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies (including require-dev)
Package operations: 471 installs, 0 updates, 0 removals
  - Installing laminas/laminas-dependency-plugin (1.0.4): Downloading (100%)         
  - Installing psr/container (1.1.1): Downloading (100%)         
(途中略)
Writing lock file
Generating autoload files
75 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PHP CodeSniffer Config installed_paths set to ../../codeception,../../magento/magento-coding-standard,../../phpcompatibility/php-compatibility

Magento的安装配置

进行设置。

$ bin/magento setup:install \
--base-url="http://<your url>/" \
--db-host=localhost \
--db-name=magento2 \
--db-user=magentip \
--db-password="<your password>" 
Starting Magento installation:
File permissions check...
[Progress: 1 / 992]
Required extensions check...
[Progress: 2 / 992]
Enabling Maintenance Mode...
[Progress: 3 / 992]
Installing deployment configuration..
(途中略)
[Progress: 991 / 992]
Write installation date...
[Progress: 992 / 992]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_o9ymoa
Nothing to import.

最后显示的/admin_o9ymoa将成为配置页面的访问地址(将显示随机字符串)。

更改文件的权限

更改位於DocumentRoot下的資料夾和文件的擁有者和權限。

$ cd /var/www/html
$ sudo chown -R magento_user:www-data .
$ find . -type d -exec chmod 770 {} \;
$ find . -type f -exec chmod 660 {} \;
$ chmod 770 bin/magento

部署 (bù shǔ)

如果不执行此操作,Magento上的内容将无法编译。

$  php bin/magento deploy:mode:set production
Enabling maintenance mode
Starting compilation
Compilation was started.
%message% 0/8 [>---------------------------]   0% < 1 sec 76.5 MiBProxies code generation... 0/8 [>---------------------------]   0% < 1 sec 76.5 MiB
Proxies code generation... 1/8 [===>------------------------]  12% 1 sec 78.5 MiB
Repositories code generation... 1/8 [===>------------------------]  12% 1 sec 78.5 MiB
Repositories code generation... 2/8 [=======>--------------------]  25% 16 secs 205.0 MiB
Service data attributes generation... 2/8 [=======>--------------------]  25% 16 secs 205.0 MiB
Application code generator... 3/8 [==========>-----------------]  37% 16 secs 205.0 MiB
Application code generator... 4/8 [==============>-------------]  50% 24 secs 227.0 MiB
Interceptors generation... 4/8 [==============>-------------]  50% 24 secs 227.0 MiB
Interceptors generation... 5/8 [=================>----------]  62% 38 secs 257.0 MiB
Area configuration aggregation... 5/8 [=================>----------]  62% 38 secs 257.0 MiB
Area configuration aggregation... 6/8 [=====================>------]  75% 45 secs 349.0 MiB
Interception cache generation... 6/8 [=====================>------]  75% 45 secs 349.0 MiB
Interception cache generation... 7/8 [========================>---]  87% 51 secs 349.0 MiB
App action list generation... 7/8 [========================>---]  87% 51 secs 349.0 MiB
App action list generation... 8/8 [============================] 100% 51 secs 349.0 MiB
Generated code and dependency injection configuration successfully.
Compilation complete
Starting deployment of static content

Deploy using quick strategy
frontend/Magento/blank/en_US            2345/2345           ============================ 100%   7 secs
adminhtml/Magento/backend/en_US         2438/2438           ============================ 100%   7 secs
frontend/Magento/luma/en_US             2362/2362           ============================ 100%   7 secs

Execution time: 25.704952001572
Deployment of static content complete
Disabling maintenance mode
Enabled production mode.

尽管内部是空的,但仍然显示出来。

image.png

添加Magento管理员用户

因为尚未进行Magento2的管理员相关设置,所以需要添加设置。

$ $ php bin/magento admin:user:create
Admin user: admin
Admin password: <admin-password>
Admin email: <your-e-mail-address>
Admin first name: <your-first-name>
Admin last name: <your-last-name>
Created Magento administrator user named admin

管理界面

如果在网站的URL中添加刚才提到的管理员路径/admin_o9ymoa,您就可以进入管理界面。

image.png

安装样本数据

为了实现这一点,我特意安装了Magento 2.3.5。是否可行呢?

切换至开发者模式

image.png
$ php bin/magento deploy:mode:show
Current application mode: production. (Note: Environment variables may override this value.)

切换为开发者模式。请按照以下步骤进行操作。

$ rm -rf ./generated/metadata/* ./generated/code/*
$ php bin/magento deploy:mode:set developer
$ php bin/magento deploy:mode:show
Current application mode: developer. (Note: Environment variables may override this value.)

转变了。

部署样本数据

$  php bin/magento sampledata:deploy
<warning>Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html</warning>
    Authentication required (repo.magento.com):
      Username: <your public key>
      Password: <your private key>
Do you want to store credentials for repo.magento.com in /var/www/html/var/composer_home/auth.json ? [Yn] Y
<warning>Warning from https://repo.packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/</warning>
Info from https://repo.packagist.org: #StandWithUkraine
./composer.json has been updated
Loading composer repositories with package information
<warning>Warning from https://repo.packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/</warning>
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies (including require-dev)
(途中省略)
Writing lock file
Generating autoload files
75 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PHP CodeSniffer Config installed_paths set to ../../magento/magento-coding-standard,../../phpcompatibility/php-compatibility,../../codeception

接着下来,执行以下命令。

$ php ./bin/magento setup:upgrade
Cache types config flushed successfully
Cache cleared successfully
File system cleanup:
(途中省略)
Module 'Yotpo_Yotpo':
Enabling caches:
Current status:
Array
(
    [layout] => 1
    [block_html] => 1
    [full_page] => 1
)

Nothing to import.

好像进展得不错。

定时任务(cron)的设置

本来应该在Magento2安装时执行,但之前在安装示例数据时出现了与cron相关的错误,所以我们故意在这里执行。此处参考了这篇文章。需要将当前用户更改为magento_user并执行注册cron。

$ cd /var/www/html/
$ php ./bin/magento cron:install --force
Crontab has been generated and saved

我会查看内容。

$ crontab -l

#~ MAGENTO START 69dd2b02e1f3a65918182048ea4e29979a849d8942e8f53ed20a4bf10e529b36
* * * * * /usr/bin/php8.1 /var/www/html/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/html/var/log/magento.cron.log
#~ MAGENTO END 69dd2b02e1f3a65918182048ea4e29979a849d8942e8f53ed20a4bf10e529b36

结果可能只有一个选项,母语为中文。

image.png
广告
将在 10 秒后关闭
bannerAds