Magento · 10 min read · Oct 20, 2025

Ubuntu 22.04にNginxとElasticsearchを使用してMagento eCommerceをインストールする方法

MagentoはPHPで書かれたオープンソースのeコマースプラットフォームです。2018年にAdobeに買収され、Adobe eCommerceと名付けられました。また、商業用およびクラウドベースの製品としても提供されています。Magentoを使用すると、高容量のプロフェッショナルなショッピングウェブサイトを作成できます。単一店舗モードと複数店舗モードの両方を提供しています。機能を拡張するための多くのモジュールが付属しています。

このチュートリアルでは、Magentoのオープンソースコミュニティ版をインストールします。プロフェッショナルなオンラインストアを設定するために必要なすべての機能を提供します。また、製品カタログを検索するためのElasticsearch、セッションおよびファイルキャッシュ用のRedisをインストールし、Nginxサーバーを使用して提供します。

前提条件

  • 最低2GBのRAMを搭載したUbuntu 22.04を実行しているサーバー。要件に応じて、より多くのRAMが必要になる場合があります。
  • sudo権限を持つ非rootユーザー。
  • サーバー用の完全修飾ドメイン名(FQDN)、magento.example.com
  • すべてが更新されていることを確認してください。 $ sudo apt update $ sudo apt upgrade
  • システムに必要な数パッケージ。 $ sudo apt install wget curl nano software-properties-common dirmngr apt-transport-https gnupg2 ca-certificates lsb-release ubuntu-keyring unzip -y これらのパッケージのいくつかは、すでにシステムにインストールされている可能性があります。

ステップ1 - ファイアウォールの設定

最初のステップは、ファイアウォールを設定することです。Ubuntuにはデフォルトでufw(Uncomplicated Firewall)が付属しています。

ファイアウォールが実行中かどうかを確認します。

$ sudo ufw status

次の出力が得られるはずです。

Status: inactive

SSHポートを許可して、ファイアウォールを有効にするときに現在の接続が切断されないようにします。

$ sudo ufw allow OpenSSH

HTTPおよびHTTPSポートも許可します。

$ sudo ufw allow http
$ sudo ufw allow https

ファイアウォールを有効にします。

$ sudo ufw enable
コマンドは既存のssh接続を中断する可能性があります。操作を続行しますか(y|n)? y
ファイアウォールはアクティブで、システム起動時に有効になります

再度ファイアウォールの状態を確認します。

$ sudo ufw status

同様の出力が表示されるはずです。

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443                        ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)

ステップ2 - PHPとその拡張機能のインストール

Ubuntu 22.04には、少し古いPHP 8.1.2バージョンが付属しています。最新のPHP 8.2バージョンをOndrejのPHPリポジトリを使用してインストールします。

$ sudo add-apt-repository ppa:ondrej/php

次に、Magentoに必要なPHPとその拡張機能をインストールします。

$ sudo apt install php8.2-fpm php8.2-mysql php8.2-bcmath php8.2-xml php8.2-zip php8.2-curl php8.2-mbstring php8.2-gd php8.2-tidy php8.2-intl php8.2-cli php8.2-soap php8.2-xsl libsodium-dev libsodium23 libssl-dev libcurl14-openssl-dev

インストールを確認します。

$ php --version
PHP 8.2.5 (cli) (built: Apr 14 2023 04:27:02) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.5, Copyright (c), by Zend Technologies

ステップ3 - Composerのインストール

ComposerはPHPの依存関係管理ツールであり、Magentoのインストールに必要です。

次のコマンドを実行してComposerバイナリをダウンロードします。MagentoはComposer 2.2 LTSを必要とするため、コマンドをそれに応じて修正しました。

$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php composer-setup.php --2.2
$ php -r "unlink('composer-setup.php');"

バイナリを/usr/local/binディレクトリに移動してComposerをインストールします。

$ sudo mv composer.phar /usr/local/bin/composer

そのバージョンを確認してインストールを確認します。

$ composer --version
Composer version 2.2.21 2023-02-15 13:07:40

ステップ4 - MySQLのインストール

Ubuntu 22.04には最新のMySQLバージョンが付属しています。単一のコマンドでインストールできます。

$ sudo apt install mysql-server

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

$ mysql --version
mysql  Ver 8.0.33-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))

このステップはMySQLバージョン8.0.28以上に必要です。MySQLシェルに入ります。

$ sudo mysql

次のコマンドを実行してrootユーザーのパスワードを設定します。数字、大文字、小文字、特殊文字を組み合わせて設定してください。

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourPassword12!';

シェルを終了します。

mysql> exit

MySQLのセキュアインストールスクリプトを実行します。

$ sudo mysql_secure_installation

最初にrootパスワードを求められます。入力してください。次に、Validate Password Componentをインストールするかどうかを尋ねられます。これはMySQLで使用されるパスワードの強度をチェックします。インストールするにはYを押します。次に、パスワード検証ポリシーのレベルを設定するように求められます。最も強力な2を選択してください。

Securing the MySQL server deployment.

Enter password for user root:

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Using existing password for root.

Estimated strength of the password: 100

次に、rootパスワードを変更しないことを拒否するためにNを入力します。また、匿名ユーザーを削除し、リモートrootログインを禁止し、テストデータベースを削除し、特権テーブルを再読み込みするためにYを入力します。

Change the password for root ? ((Press y|Y for Yes, any other key for No) : N

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

ステップ5 - MySQLの設定

MySQLシェルにログインします。プロンプトが表示されたら、rootパスワードを入力します。

$ sudo mysql -u root -p

Magento用のデータベースを作成します。

mysql> CREATE DATABASE magento;

SQLユーザーアカウントを作成します。

mysql> CREATE USER 'magentouser'@'localhost' IDENTIFIED BY 'Your_password2';

ユーザーにデータベースへのすべての権限を付与します。

mysql> GRANT ALL PRIVILEGES ON magento.* TO 'magentouser'@'localhost';

ユーザー権限をフラッシュします。

mysql> FLUSH PRIVILEGES;

シェルを終了します。

mysql> exit

ステップ6 - Nginxのインストール

Ubuntu 22.04には古いバージョンのNginxが付属しています。最新バージョンをインストールするには、公式のNginxリポジトリをダウンロードする必要があります。

Nginxの署名キーをインポートします。

$ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

Nginxの安定版リポジトリを追加します。

$ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg arch=amd64] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list

システムリポジトリを更新します。

$ sudo apt update

Nginxをインストールします。

$ sudo apt install nginx

インストールを確認します。

$ nginx -v
nginx version: nginx/1.24.0

Nginxサーバーを起動します。

$ sudo systemctl start nginx

ステップ7 - SSLのインストール

SSL証明書を生成するためにCertbotをインストールする必要があります。Ubuntuのリポジトリを使用してCertbotをインストールするか、Snapdツールを使用して最新バージョンを取得できます。Snapdバージョンを使用します。

Ubuntu 22.04にはデフォルトでSnapdがインストールされています。次のコマンドを実行して、Snapdのバージョンが最新であることを確認します。

$ sudo snap install core && sudo snap refresh core

Certbotをインストールします。

$ sudo snap install --classic certbot

次のコマンドを使用して、Certbotコマンドが/usr/binディレクトリにシンボリックリンクを作成することで実行できるようにします。

$ sudo ln -s /snap/bin/certbot /usr/bin/certbot

次のコマンドを実行してSSL証明書を生成します。

$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [email protected] -d magento.example.com

上記のコマンドは、サーバーの/etc/letsencrypt/live/magento.example.comディレクトリに証明書をダウンロードします。

Diffie-Hellmanグループ証明書を生成します。

$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096

Certbotの更新スケジューラーサービスを確認します。

$ sudo systemctl list-timers

snap.certbot.renew.serviceがスケジュールされたサービスの1つとして表示されます。

NEXT                        LEFT          LAST                        PASSED        UNIT                      ACTIVATES
.....
Sun 2023-02-26 06:32:00 UTC 9h left       Sat 2023-02-25 18:04:05 UTC 2h 59min ago  snap.certbot.renew.timer  snap.certbot.renew.service
Sun 2023-02-26 06:43:20 UTC 9h left       Sat 2023-02-25 10:49:23 UTC 10h ago       apt-daily-upgrade.timer   apt-daily-upgrade.service
Sun 2023-02-26 09:00:06 UTC 11h left      Sat 2023-02-25 20:58:06 UTC 5min ago      apt-daily.timer           apt-daily.service

SSL更新が正常に機能しているかどうかを確認するために、プロセスのドライランを行います。

$ sudo certbot renew --dry-run

エラーが表示されなければ、すべて設定完了です。証明書は自動的に更新されます。

ステップ8 - Elasticsearchのインストール

ElasticsearchはMagentoで製品検索に使用されます。Magentoと互換性のあるバージョンであるため、公式リポジトリを使用してElasticsearch 7.xをインストールします。

ElasticsearchのGPGキーをインポートします。

$ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

Elasticsearchリポジトリを追加します。

$ echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list

システムのリポジトリリストを更新します。

$ sudo apt update

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

$ sudo apt install elasticsearch

Elasticsearchは多くのメモリを使用します。サーバーのサイズに応じて使用量を制限する必要があります。/etc/elasticsearch/jvm.options.d/memory.optionsファイルを作成し、編集のために開きます。

$ sudo nano /etc/elasticsearch/jvm.options.d/memory.options

次のコードを貼り付けます。

-Xms1g
-Xmx1g

ファイルを保存するには、Ctrl + Xを押し、プロンプトが表示されたらYを入力します。これにより、Elasticsearchは1GBのRAMを使用するように設定されます。必要に応じて任意の値を使用できます。

サービスを開始して有効にします。

$ sudo systemctl enable elasticsearch --now

Elasticsearchが動作しているかどうかを確認します。

$ curl http://localhost:9200

次の出力が表示されるはずです。

{
  "name" : "magento",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "6yks8tZ6T4GskIwWoXuSLA",
  "version" : {
    "number" : "7.17.10",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "fecd68e3150eda0c307ab9a9d7557f5d5fd71349",
    "build_date" : "2023-04-23T05:33:18.138275597Z",
    "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"
}

ステップ9 - Redisサーバーのインストール

MagentoはセッションおよびキャッシュストレージにRedisを使用します。これは完全にオプションであり、データベースをセッションストレージとして使用できます。しかし、Redisはより良い仕事をします。最新バージョンのMagentoはRedis 7.0で動作します。UbuntuにはRedis 6.0が付属しているため、インストールにはRedisリポジトリを使用します。

公式のRedis GPGキーをインポートします。

$ curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

APTリポジトリをソースリストに追加します。

$ echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

システムリポジトリリストを更新します。

$ sudo apt update

Redisサーバーをインストールするために次のコマンドを発行します。

$ sudo apt install redis

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

$ redis-server -v
Redis server v=7.0.11 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=3af367a78d5e21e9

次のコマンドを使用してサービス接続を確認します。

$ redis-cli

Redisシェルに切り替わります。

最初のステップは、Redisのデフォルトユーザーのパスワードを設定することです。Your_Redis_Passwordを選択した強力なパスワードに置き換えます。パスワードの前に>文字を付けてください。

127.0.0.1:6379> acl setuser default >Your_Redis_Password

Redis認証をテストします。

127.0.0.1:6379> AUTH Your_Redis_Password
OK

サービスにPingを送ります。

127.0.0.1:6379> ping
PONG

exitと入力してサービスを終了します。

ステップ10 - Magentoのダウンロード

Magento用のウェブルートディレクトリを作成します。

$ sudo mkdir /var/www/magento -p

Magentoディレクトリの権限を現在のユーザーに付与します。

$ sudo chown $USER:$USER /var/www/magento/ -R

/var/wwwディレクトリに移動します。

$ cd /var/www

次に進む前に、Magentoリポジトリに必要な認証キーを取得する必要があります。https://account.magento.com/のウェブサイトにアクセスすると、Adobe IDを使用してログインするように求められるページが表示されます。

Adobe ID サインインページ

Adobe IDでサインインボタンをクリックして、次のページに移動します。

Magento Adobeログインページ

Adobe IDをお持ちの場合は、資格情報を入力して続行します。ここでアカウントを作成することもできます。アカウントを作成してログインしたら、https://marketplace.magento.com/customer/accessKeys/のURLを開きます。このページには、プロフィールにアクセスしてアクセスキーリンクをクリックすることでもアクセスできます。

Adobe Magentoプロフィール アクセスキーのページ

新しいアクセスキーを作成ボタンをクリックして、認証キーを作成します。識別のためにキーに名前を付けます。

Magento アクセスキー

次のステップのために、公開キーと秘密キーの両方をメモしておいてください。

Magentoプロジェクトを作成します。

$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento

リポジトリのユーザー名とパスワードを求められます。公開キーをユーザー名として、秘密キーをパスワードとして使用します。Composer構成ディレクトリに資格情報を保存するかどうかを尋ねられます。yと入力して保存します。

Creating a "magento/project-community-edition" project at "./magento"
    Authentication required (repo.magento.com):
      Username: 53211xxxxxxxxxxxxxxxxxxxxxxxxxxx
      Password:
Do you want to store credentials for repo.magento.com in /home/navjot/.config/composer/auth.json ? [Yn] y
Installing magento/project-community-edition (2.4.6)
  - Downloading magento/project-community-edition (2.4.6)
  - Installing magento/project-community-edition (2.4.6): Extracting archive
Created project in /var/www/magento
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Lock file operations: 564 installs, 0 updates, 0 removals
  - Locking 2tvenom/cborencode (1.0.2)
  - Locking adobe-commerce/adobe-ims-metapackage (2.2.0)
...............................................

次のコマンドを実行してファイルの権限を設定し、Magentoバイナリを実行可能にします。また、Magentoディレクトリの所有者をNginxユーザーに設定して、ウェブサイトにアクセスできるようにします。

$ cd /var/www/magento/
$ sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
$ sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
$ sudo chown -R :nginx .
$ sudo chmod u+x bin/magento

ステップ11 - Magentoのインストール

Magentoディレクトリにいることを確認してください。

$ cd /var/www/magento

次のコマンドを実行してMagentoをインストールします。

$ bin/magento setup:install \
--base-url=http://magento.example.com \
--use-secure=1 \
--base-url-secure=https://magento.example.com \
--use-secure-admin=1 \
--db-host=localhost \
--db-name=magento \
--db-user=magentouser \
--db-password=Your_password2 \
--admin-firstname=Navjot \
--admin-lastname=Singh \
[email protected] \
--admin-user=navjot \
--admin-password=admin_password \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1 \
--elasticsearch-host=http://127.0.0.1 \
--elasticsearch-port=9200 \
--session-save=redis \
--session-save-redis-db=0 \
--session-save-redis-password=redis_password \
--cache-backend=redis \
--cache-backend-redis-db=2 \
--cache-backend-redis-password=redis_password \
--page-cache=redis \
--page-cache-redis-db=4 \
--page-cache-redis-password=redis_password

プロセスが完了すると、次のような出力が得られます。

.......
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_19uadb
Nothing to import.

管理パネルにアクセスするために必要なAdmin URIをメモしておいてください。

Magentoのcronジョブを作成します。

$ php bin/magento cron:install

cronジョブを確認します。

$ crontab -l

次の出力が表示されるはずです。

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

ステップ12 - PHP-FPMの設定

/etc/php/8.2/fpm/pool.d/www.confファイルを開きます。

$ sudo nano /etc/php/8.2/fpm/pool.d/www.conf

PHPプロセスのUnixユーザー/グループをnginxに設定する必要があります。ファイル内のuser=www-dataおよびgroup=www-data行を見つけて、nginxに変更します。

...
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
...

ファイル内のlisten.owner = www-dataおよびlisten.group = www-data行を見つけて、nginxに変更します。

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions. The owner
; and group can be specified either by name or by their numeric IDs.
; Default Values: user and group are set as the running user
;                 mode is set to 0660
listen.owner = nginx
listen.group = nginx

ファイルを保存するには、Ctrl + Xを押し、プロンプトが表示されたらYを入力します。

PHP-FPMおよびPHP-CLIの実行時間を180秒に増やします。

$ sudo sed -i 's/max_execution_time = 30/max_execution_time = 180/' /etc/php/8.2/fpm/php.ini
$ sudo sed -i 's/max_execution_time = 30/max_execution_time = 180/' /etc/php/8.2/cli/php.ini

PHP-FPMのメモリ制限を128MBから256MBに増やします。サーバーのサイズや要件に応じて制限を引き上げることができます。

$ sudo sed -i 's/memory_limit = 128M/memory_limit = 256M/' /etc/php/8.2/fpm/php.ini

Magentoはデフォルトでメディアライブラリのファイルサイズ制限を2MBに設定しています。次のコマンドを実行してファイルサイズ制限を25MBに増やします。

$ sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 25M/g' /etc/php/8.2/fpm/php.ini
$ sudo sed -i 's/post_max_size = 8M/post_max_size = 25M/g' /etc/php/8.2/fpm/php.ini

Zlib圧縮をオンにします。

$ sudo sed -i 's/zlib.output_compression = Off/zlib.output_compression = On/g' /etc/php/8.2/fpm/php.ini

PHP-FPMサービスを再起動します。

$ sudo systemctl restart php8.2-fpm

PHPセッションディレクトリのグループをNginxに変更します。

$ sudo chgrp -R nginx /var/lib/php/sessions

ステップ13 - Nginxの設定

/etc/nginx/nginx.confファイルを編集のために開きます。

$ sudo nano /etc/nginx/nginx.conf

include /etc/nginx/conf.d/*.conf;の前に次の行を追加します。

server_names_hash_bucket_size  64;

ファイルを保存するには、Ctrl + Xを押し、プロンプトが表示されたらYを入力します。

/etc/nginx/conf.d/magento.confファイルを作成して開きます。

$ sudo nano /etc/nginx/conf.d/magento.conf

次のコードを貼り付けます。

upstream fastcgi_backend {
  server  unix:/run/php/php8.2-fpm.sock;
}

server {
  # Redirect any http requests to https
  listen 80;
  listen [::]:80;
  server_name magento.example.com;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  server_name magento.example.com;

  set $MAGE_ROOT /var/www/magento;
  include /var/www/magento/nginx.conf.sample;
  client_max_body_size 25m;

  access_log /var/log/nginx/magento.access.log;
  error_log  /var/log/nginx/magento.error.log;

  # TLS configuration
  ssl_certificate /etc/letsencrypt/live/magento.example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/magento.example.com/privkey.pem;
  ssl_trusted_certificate /etc/letsencrypt/live/magento.example.com/chain.pem;
  ssl_protocols TLSv1.2 TLSv1.3;

  ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
  ssl_prefer_server_ciphers on;
  ssl_session_cache shared:SSL:50m;
  ssl_session_timeout 1d;

  # OCSP Stapling ---
  # fetch OCSP records from URL in ssl_certificate and cache them
  ssl_stapling on;
  ssl_stapling_verify on;
  ssl_dhparam /etc/ssl/certs/dhparam.pem;
}

ファイルを保存するには、Ctrl + Xを押し、プロンプトが表示されたらYを入力します。

Magentoには、/var/www/magento/nginx.conf.sampleにNginx設定テンプレートが付属しており、私たちの設定に含めています。$MAGE_ROOT変数は、私たちがファイルに設定したMagentoのウェブルートディレクトリを指し、サンプル設定ファイルで使用されます。

Nginxの設定ファイル構文を確認します。

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Nginxサービスを再起動します。

$ sudo systemctl restart nginx

https://magento.example.comのURLを介してMagentoウェブサイトを開きます。次のページが表示されるはずです。

Magento ホームページ

CSSとJSが読み込まれない場合は、次のコマンドを実行します。

$ cd /var/www/magento
$ php bin/magento setup:static-content:deploy -f
$ php bin/magento indexer:reindex

ステップ14 - 二要素認証の無効化

管理パネルにアクセスする前に、デフォルトで有効になっている二要素認証を無効にする必要があります。Magentoはインストール中に二要素認証を有効にするためにsendmail経由でメールを送信しようとしますが、私たちはそれを設定していないため、ダッシュボードにアクセスする唯一の方法は、最初にこの機能を無効にすることです。

サーバーにsendmailが設定されている場合は、このステップをスキップできます。二要素認証を無効にするには、次のコマンドを使用してMagentoのモジュールを2つ無効にする必要があります。

$ php /var/www/magento/bin/magento module:disable Magento_AdminAdobeImsTwoFactorAuth
$ php /var/www/magento/bin/magento module:disable Magento_TwoFactorAuth

次のコマンドを実行してクラスを作成します。

$ php /var/www/magento/bin/magento setup:di:compile

キャッシュもクリアします。

$ php /var/www/magento/bin/magento c:c

ステップ15 - 管理ポータルにアクセス

Magentoインストールスクリプトが提供したURIを使用して管理ポータルを開く必要があります。もしメモを取るのを忘れた場合や失った場合は、次のコマンドを使用してURIを再取得できます。

$ php /var/www/magento/bin/magento info:adminuri
Admin URI: /admin_19uadb

ブラウザでhttps://magento.example.com/admin_19uadbのURLを開くと、次の画面が表示されます。

Magento 管理ダッシュボードログインページ

インストール中に提供された管理者資格情報を入力し、サインインボタンをクリックして続行します。次の画面が表示されます。

Magento 管理ダッシュボード

Adobeに使用データを収集する許可を求めるポップアップが表示されます。許可しないボタンをクリックして続行します。

次のステップは、二要素認証を再有効にするためにメールのSMTPを設定することです。Stores >> Configurationメニューにアクセスします。

Magento Stores >> Config メニュー

左側からAdvanced Menuを展開し、Systemsオプションをクリックしてメール設定ページを開きます。

Magento メール送信設定

Transport, Host, Portオプションの前にあるシステム値を使用のチェックを外します。Transportのドロップダウンメニューをクリックし、SMTPを選択します。このチュートリアルでは、Amazon SESをメール送信者として使用します。

Magento Amazon SESメール設定

SMTPホスト、ポート587、ユーザー名、パスワードを入力し、AuthLOGINに設定し、SSLTLSに設定します。完了したら、設定を保存ボタンをクリックします。メール設定を構成したので、次のステップはストアのメールIDを設定してテストすることです。

同じページでGeneralメニューを展開し、Store Email Addressesオプションを選択します。

Magento ストアメールアドレスページ

デフォルトの送信者メールフィールドのチェックを外し、ストアのメールIDを入力します。完了したら、設定を保存ボタンをクリックします。同様に、Contacts画面を開いて同じ変更を行い、設定を保存ボタンをクリックして完了します。

Magento お問い合わせメール設定

管理者オプションの変更はキャッシュに影響を与える可能性があり、警告が表示されます。次のコマンドを実行してキャッシュを手動でクリアします。

$ php /var/www/magento/bin/magento c:c

メールをテストするには、ストアフロントページにアクセスし、Contact Usページを開きます。直接https://magento.example.com/contact/のURLを使用してアクセスできます。テストメッセージを送信し、送信ボタンをクリックします。類似のメールを受信するはずです。

Magento テストメール

ステップ16 - 二要素認証の有効化と設定

SMTPメール送信者を有効にしたので、二要素認証を再度有効にする時が来ました。次のコマンドを実行して二要素認証を有効にします。

$ php /var/www/magento/bin/magento module:enable Magento_AdminAdobeImsTwoFactorAuth
$ php /var/www/magento/bin/magento module:enable Magento_TwoFactorAuth

モジュールのセットアップをアップグレードします。

$ php /var/www/magento/bin/magento setup:upgrade

次のコマンドを実行してクラスを作成します。

$ php /var/www/magento/bin/magento setup:di:compile

キャッシュもクリアします。

$ php /var/www/magento/bin/magento c:c

管理エリアにアクセスできない場合は、次のコマンドも実行します。

静的コンテンツを強制的にデプロイします。

$ php /var/www/magento/bin/magento setup:static-content:Deploy -f

ファイルの権限を設定します。

$ cd /var/www/magento
$ sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
$ sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
$ sudo chown -R :nginx .

管理ポータルにアクセスすると、次の画面が表示されます。

Magento 2FA 設定

Google Authenticatorメソッドを使用します。ハードウェアキーがある場合は、それを使用できます。Google Authenticatorメソッドは、Authy、1Password、Bitwarden、Microsoft Authenticatorなど、任意のTOTPアプリで動作します。適用ボタンをクリックして続行します。

Magento Google 2FA 設定

次のページでは、2FAアプリでスキャンするQRコードが表示されます。アプリに詳細を入力し、生成されたコードをAuthenticator codeフィールドにコピーします。確認ボタンをクリックして管理ダッシュボードに進みます。

結論

これで、NginxサーバーとElasticsearchを使用してUbuntu 22.04サーバーにMagento eCommerceサイトをインストールするチュートリアルが終了します。質問がある場合は、下のコメントに投稿してください。

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。