オブジェクト指向とかデザインパターンとか開発プロセスとかツールとか

satoshi's ソフトウェア開発

js






当サイトはアフィリエイト広告を利用してます。

GCP magento

GCEでmagentoを動かしてみた

更新日:


magentoを使いたいという要望が聞こえてきたので、とりあえずインストールして動かすところまでやってみようと思いました。

まずはシステム要件の確認です。

公式サイトを見るに限ります。

インストールガイドがこちら。手順がアイコンで表示されているのでわかりやすいです。

Installation flow | Adobe Commerce Developer Guide

システム要件を確認してみます。

System requirements | Adobe Commerce Developer Guide

GCEでUbuntuのインスタンスを持ってるので、そこにインストールしてみます。

最初にComposerをインストールします。

 

satoshis@host:~$ sudo apt install composer
Reading package lists... Done
Building dependency tree       
Reading state information... Done
(略)
After this operation, 16.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

ElasticSearchも必要と書いてあるので、インストールします。
ElasticSearchはJavaが必要です。Javaのバージョンを確認します。

satoshis@host:~$ java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~18.04-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

Javaをインストールしてない場合は、インストールしてください。

satoshis@host:~$ sudo apt-get install -y openjdk-8-jdk

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

satoshis@host:~$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.1-linux-x86_64.tar.gz
satoshis@host:~$ tar -xzf elasticsearch-7.13.1-linux-x86_64.tar.gz
satoshis@host:~$ cd elasticsearch-7.13.1

自分のディレクトリ内に展開してしまいました。
まあ、動かしてみるだけなので、ここでいいことにします。
デーモンとして起動します。

satoshis@host:~$ cd elasticsearch-7.13.1/
satoshis@host:~/elasticsearch-7.13.1$ bin/elasticsearch -d

起動するまでにちょっと時間がかかります。
しばらく待ってから curl でアクセスしてみます。

satoshis@host:~/elasticsearch-7.13.1$ curl "localhost:9200"
{
  "name" : "host.satoshis.jp",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "GC5K9NgAQOWSKiFHmhf67Q",
  "version" : {
    "number" : "7.13.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "9a7758028e4ea59bcab41c12004603c5a7dd84a9",
    "build_date" : "2021-05-28T17:40:59.346932922Z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.2",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

動いてるみたいです。

次に、composerでmagentoをインストールするのですが、途中でUsernameとPasswordを聞かれます。
UsernameとPasswordは、Magentoのサイトからコピーしてくる必要があります。
このUsernameとPasswordの場所がわかりにくいです。

Magento Marketplaceにアクセスしてログインし、My Profileをクリックします。

Access Keys をクリックします。

最初はなにもない状態なので「Create A New Access Key」をクリックしてアクセスキーを作成します。
名前は適当でいいです。指定した名前は、左側に表示されます。
ここに表示された Public Key が Username で、Private Key が Password です。

Composerでmagentoをインストールします。
sudo で Composer を使うのはよろしくないのですが、お試しインストールなのでrootで実行してもいいことにします。

satoshis@host:/var/www$ sudo composer create-project --repository=https://repo.magento.com/ magento/project-community-edition=2.3.5 /var/www/magento
Do not run Composer as root/super user! See https://getcomposer.org/root for details
                                                                                    
    Authentication required (repo.magento.com):
      Username: (Public Keyを入力)
      Password: (Private Keyを入力)
Do you want to store credentials for repo.magento.com in /home/satoshis/.composer/auth.json ? [Yn] y
Installing magento/project-community-edition (2.3.5)

In ZipDownloader.php line 68:
                                                                                    
  The zip extension and unzip command are both missing, skipping.                   
  Your command-line PHP is using multiple ini files. Run `php --ini` to show them.  
                                                                                    

create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]

zip extension がないよ!と怒られました。
他にも、上記のシステム要件で指定されているエクステンションをインストールしておきます。

satoshis@host:/var/www$ sudo apt-get install php7.2-bcmath php7.2-gd php7.2-intl php7.2-mbstring php7.2-soap php7.2-xsl php7.2-zip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
(略)

Creating config file /etc/php/7.2/mods-available/intl.ini with new version
Processing triggers for libc-bin (2.27-3ubuntu1.2) ...
Processing triggers for php7.2-fpm (7.2.34-22+ubuntu18.04.1+deb.sury.org+1) ...
Processing triggers for php7.2-cli (7.2.34-22+ubuntu18.04.1+deb.sury.org+1) ...

再び、magentoのインストールにチャレンジします。
さきほどはUsernameとPasswordを聞かれたのですが、二度目以降は保存されているらしく、聞かれずに先に進んでくれます。

satoshis@host:/var/www$ sudo composer create-project --repository=https://repo.magento.com/ magento/project-community-edition=2.3.5 /var/www/magento
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Installing magento/project-community-edition (2.3.5)
  - Installing magento/project-community-edition (2.3.5): Downloading (100%)         
Created project in /var/www/magento
Loading composer repositories with package information
Warning from https://packagist.org: You are using an outdated version of Composer. Composer 2 is now available and you should upgrade. See https://getcomposer.org/2
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires dealerdirect/phpcodesniffer-composer-installer ^0.5.0 -> satisfiable by dealerdirect/phpcodesniffer-composer-installer[v0.5.0].
    - dealerdirect/phpcodesniffer-composer-installer v0.5.0 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.1.0] but it does not match the constraint.
  Problem 2
    - laminas/laminas-dependency-plugin[1.0.0, ..., 1.0.4] require composer-plugin-api ^1.1 -> found composer-plugin-api[2.1.0] but it does not match the constraint.
    - magento/product-community-edition 2.3.5 requires laminas/laminas-dependency-plugin ^1.0 -> satisfiable by laminas/laminas-dependency-plugin[1.0.0, ..., 1.0.4].
    - Root composer.json requires magento/product-community-edition 2.3.5 -> satisfiable by magento/product-community-edition[2.3.5].

なんかエラーが出ました。

ぐぐってみると、composerは1系でないと対応してないっぽいです。
1系の最新は1.10.22なので、composerをダウングレードします。

satoshis@host:/var/www$ composer self-update 1.10.22
Upgrading to version 1.10.22 (stable channel).
   
Use composer self-update --rollback to return to version 2.1.2

もう一度、magentoのインストールにチャレンジします。
インストール先のディレクトリがあるとエラーになるので、削除してからやり直します。

satoshis@host:/var/www$ sudo rm -fr /var/www/magento
satoshis@host:/var/www$ sudo composer create-project --repository=https://repo.magento.com/ magento/project-community-edition=2.3.5 /var/www/magento
(略)
Generating autoload files
70 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

なんか、無事にインストールが終わったようです。

次はデータベースを用意します。

MySqlを未インストールだったらインストールします。

satoshis@host:~$ sudo apt install mysql-server

インストールが終わったら、ステータスを確認してみましょう。

satoshis@host:~$ sudo service mysql status
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2021-06-08 07:20:36 UTC; 34s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 19094 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 19133 (mysqld)
   Status: "Server is operational"
    Tasks: 38 (limit: 4368)
   CGroup: /system.slice/mysql.service
           └─19133 /usr/sbin/mysqld

Jun 08 07:20:35 host.satoshis.jp systemd[1]: Starting MySQL Community Server...
Jun 08 07:20:36 host.satoshis.jp systemd[1]: Started MySQL Community Server.

動いてるみたいです。

データベースインスタンスとユーザーを作って、ユーザーに権限を与えます。

satoshis@host:~$ mysql -u root -p

(とりあえずここまで)







-GCP, magento
-, ,

Copyright© satoshi's ソフトウェア開発 , 2024 All Rights Reserved Powered by STINGER.