この記事は5分30秒で読めます。

皆さん、こんにちは! EC-CUBERの木下です。

とうとう長かった道のりも最後のSTEPとなりました。
本日は、「Amazon Linux2にEC-CUBE4.0.4をインストールする最後の手順」をご紹介したいと思います。

▼関連記事:Amazon Linux2にEC-CUBE4.0.4をインストールする手順~1~
https://ec-cuber.jp/news-column/column09/
▼関連記事:Amazon Linux2にEC-CUBE4.0.4をインストールする手順~2~
https://ec-cuber.jp/etc/column09-2/
前回までのおさらいは、こちらの記事を合わせてご覧ください^^

手順1、2とお読みいただいた皆様、大変お疲れ様でした。
最後の3STEP、張り切っていきましょう!

手順

composerインストール

ec2-userに戻ってコマンドを実行
[root@ip-X-X-X-X ~]# exit
logout
[ec2-user@ip-X-X-X-X ~]$
composerインストール
最新のインストールコマンドは、公式サイトをご覧ください。
[Download Composer](https://getcomposer.org/download/)
[ec2-user@ip-X-X-X-X ~]$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
[ec2-user@ip-X-X-X-X ~]$ php -r "if (hash_file('sha384', 'composer-setup.php') === 'e5325b19b381bfd88ce90a5ddb7823406b2a38cff6bb704b0acc289a09c8128d4a8ce2bbafcd1fcbdc38666422fe2806') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Installer verified
[ec2-user@ip-X-X-X-X ~]$ php composer-setup.php
All settings correct for using Composer
Downloading...

Composer (version 1.10.10) successfully installed to: /home/ec2-user/composer.phar
Use it: php composer.phar

[ec2-user@ip-X-X-X-X ~]$ php -r "unlink('composer-setup.php');"
[ec2-user@ip-X-X-X-X ~]$

composerにパスを通す
[ec2-user@ip-X-X-X-X ~]$ sudo mv composer.phar /usr/local/bin/composer
[ec2-user@ip-X-X-X-X ~]$

※パスを通した後、composer -v を行い、バージョンが表示されれば、composer をコマンドとして認識されております。
エラーが表示され、使用できない場合は、下記サイトを参考にしてください。

https://qiita.com/masa_stone22/items/bb56170f540391ba554d

EC-CUBEインストール

  1. ec2-userのままコマンドを実行
ドキュメントルート配下に移動する
[ec2-user@ip-X-X-X-X ~]$ cd /var/www/html/
[ec2-user@ip-X-X-X-X html]$ 

ダミーデータ作成コマンド実行のためには 公式のgitリポジトリからクローンする必要がある
[ec2-user@ip-X-X-X-X html]$ git clone https://github.com/EC-CUBE/ec-cube.git
Cloning into 'ec-cube'...
remote: Enumerating objects: 38, done.
remote: Counting objects: 100% (38/38), done.
remote: Compressing objects: 100% (36/36), done.
remote: Total 275300 (delta 12), reused 9 (delta 2), pack-reused 275262
Receiving objects: 100% (275300/275300), 130.59 MiB | 13.77 MiB/s, done.
Resolving deltas: 100% (196112/196112), done.
[ec2-user@ip-X-X-X-X html]$

bin/consoleに実行権限を付与する
※ EC-CUBEのコマンドを利用する場合は bin/console に実行権限を付与してください。
EC-CUBEのコマンドを利用する場合は bin/console に実行権限を付与してください。
[ec2-user@ip-X-X-X-X html]$ chmod 764 ec-cube/bin/console
[ec2-user@ip-X-X-X-X html]$


composer.jsonが配置されたディレクトリに移動し、composerインストールを行う
[ec2-user@ip-X-X-X-X html]$ cd ec-cube/
[ec2-user@ip-X-X-X-X ec-cube]$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 164 installs, 0 updates, 0 removals
  - Installing ocramius/package-versions (1.4.2): Downloading (100%)         
  - Installing ec-cube/plugin-installer (0.0.8): Downloading (100%)         
  - Installing kylekatarnls/update-helper (1.2.0): Downloading (100%)         
  - Installing symfony/flex (v1.8.4): Downloading (100%)         

Prefetching 160 packages 🎶 💨
  - Downloading (100%)

  - Installing symfony/process (v3.4.42): Loading from cache
  - Installing symfony/finder (v3.4.42): Loading from cache
  - Installing symfony/polyfill-ctype (v1.17.1): Loading from cache
  - Installing symfony/filesystem (v3.4.42): Loading from cache
  - Installing symfony/polyfill-mbstring (v1.17.1): Loading from cache
  - Installing psr/log (1.1.2): Loading from cache
  - Installing symfony/debug (v3.4.42): Loading from cache
  - Installing symfony/console (v3.4.42): Loading from cache
  - Installing seld/phar-utils (1.0.1): Loading from cache
  - Installing seld/jsonlint (1.7.2): Loading from cache
  - Installing justinrainbow/json-schema (5.2.9): Loading from cache
  - Installing composer/xdebug-handler (1.4.0): Loading from cache
  - Installing composer/spdx-licenses (1.5.2): Loading from cache
  - Installing composer/semver (1.5.0): Loading from cache
  - Installing composer/ca-bundle (1.2.4): Loading from cache
  - Installing composer/composer (1.9.1): Loading from cache
  - Installing doctrine/collections (1.6.4): Loading from cache
  - Installing doctrine/lexer (1.0.2): Loading from cache
  - Installing doctrine/annotations (v1.8.0): Loading from cache
  - Installing doctrine/reflection (v1.0.0): Loading from cache
  - Installing doctrine/event-manager (1.1.0): Loading from cache
  - Installing doctrine/cache (1.9.1): Loading from cache
  - Installing doctrine/persistence (1.2.0): Loading from cache
  - Installing doctrine/inflector (1.3.1): Loading from cache
  - Installing doctrine/common (v2.11.0): Loading from cache
  - Installing symfony/doctrine-bridge (v3.4.42): Loading from cache
  - Installing doctrine/doctrine-cache-bundle (1.3.5): Loading from cache
  - Installing symfony/polyfill-util (v1.17.1): Loading from cache
  - Installing symfony/polyfill-php56 (v1.17.1): Loading from cache
  - Installing paragonie/random_compat (v9.99.99): Loading from cache
  - Installing symfony/polyfill-php70 (v1.17.1): Loading from cache
  - Installing symfony/http-foundation (v3.4.42): Loading from cache
  - Installing symfony/event-dispatcher (v3.4.42): Loading from cache
  - Installing symfony/http-kernel (v3.4.42): Loading from cache
  - Installing psr/container (1.0.0): Loading from cache
  - Installing symfony/dependency-injection (v3.4.42): Loading from cache
  - Installing symfony/config (v3.4.42): Loading from cache
  - Installing doctrine/instantiator (1.3.0): Loading from cache
  - Installing doctrine/dbal (v2.9.3): Loading from cache
  - Installing doctrine/orm (v2.7.0): Loading from cache
  - Installing symfony/routing (v3.4.42): Loading from cache
  - Installing symfony/class-loader (v3.4.42): Loading from cache
  - Installing symfony/polyfill-apcu (v1.17.1): Loading from cache
  - Installing psr/simple-cache (1.0.1): Loading from cache
  - Installing psr/cache (1.0.1): Loading from cache
  - Installing symfony/cache (v3.4.42): Loading from cache
  - Installing symfony/framework-bundle (v3.4.42): Loading from cache
  - Installing jdorn/sql-formatter (v1.2.17): Loading from cache
  - Installing doctrine/doctrine-bundle (1.12.0): Loading from cache
  - Installing doctrine/data-fixtures (1.3.3): Loading from cache
  - Installing doctrine/doctrine-fixtures-bundle (3.3.0): Loading from cache
  - Installing zendframework/zend-eventmanager (3.2.1): Loading from cache
  - Installing zendframework/zend-code (3.4.0): Loading from cache
  - Installing ocramius/proxy-manager (2.1.1): Loading from cache
  - Installing doctrine/migrations (v1.8.1): Loading from cache
  - Installing egulias/email-validator (2.1.11): Loading from cache
  - Installing symfony/stopwatch (v3.4.42): Loading from cache
  - Installing symfony/polyfill-php72 (v1.17.0): Loading from cache
  - Installing symfony/options-resolver (v3.4.42): Loading from cache
  - Installing php-cs-fixer/diff (v1.3.0): Loading from cache
  - Installing friendsofphp/php-cs-fixer (v2.16.1): Loading from cache
  - Installing guzzlehttp/promises (v1.3.1): Loading from cache
  - Installing twig/twig (v2.12.2): Loading from cache
  - Installing knplabs/knp-components (v1.3.10): Loading from cache
  - Installing knplabs/knp-paginator-bundle (v2.8.0): Loading from cache
  - Installing symfony/translation (v3.4.42): Loading from cache
  - Installing nesbot/carbon (1.39.1): Loading from cache
  - Installing pimple/pimple (v1.1.1): Loading from cache
  - Installing psr/http-message (1.0.1): Loading from cache
  - Installing ralouphie/getallheaders (3.0.3): Loading from cache
  - Installing sensio/framework-extra-bundle (v5.4.1): Loading from cache
  - Installing symfony/yaml (v3.4.42): Loading from cache
  - Installing sensio/generator-bundle (v3.1.7): Loading from cache
  - Installing tecnickcom/tcpdf (6.3.2): Loading from cache
  - Installing setasign/fpdi (v2.2.0): Loading from cache
  - Installing setasign/fpdi-tcpdf (v2.2.0): Loading from cache
  - Installing skorp/detect-incompatible-samesite-useragents (1.0.0): Loading from cache
  - Installing mobiledetect/mobiledetectlib (2.8.34): Loading from cache
  - Installing suncat/mobile-detect-bundle (v1.1.1): Loading from cache
  - Installing symfony/asset (v3.4.42): Loading from cache
  - Installing symfony/var-dumper (v3.4.42): Loading from cache
  - Installing symfony/twig-bridge (v3.4.42): Loading from cache
  - Installing symfony/twig-bundle (v3.4.42): Loading from cache
  - Installing symfony/web-profiler-bundle (v3.4.42): Loading from cache
  - Installing symfony/profiler-pack (v1.0.4): Loading from cache
  - Installing monolog/monolog (1.25.2): Loading from cache
  - Installing symfony/monolog-bridge (v3.4.42): Loading from cache
  - Installing symfony/monolog-bundle (v3.5.0): Loading from cache
  - Installing symfony/debug-bundle (v3.4.42): Loading from cache
  - Installing symfony/debug-pack (v1.0.8): Loading from cache
  - Installing symfony/dotenv (v3.4.42): Loading from cache
  - Installing symfony/expression-language (v3.4.42): Loading from cache
  - Installing symfony/inflector (v3.4.42): Loading from cache
  - Installing symfony/property-access (v3.4.42): Loading from cache
  - Installing symfony/intl (v3.4.42): Loading from cache
  - Installing symfony/polyfill-intl-icu (v1.17.1): Loading from cache
  - Installing symfony/form (v3.4.42): Loading from cache
  - Installing nikic/php-parser (v4.3.0): Loading from cache
  - Installing symfony/maker-bundle (v1.19.0): Loading from cache
  - Installing doctrine/doctrine-migrations-bundle (v1.3.2): Loading from cache
  - Installing symfony/orm-pack (v1.0.8): Loading from cache
  - Installing symfony/polyfill-iconv (v1.17.1): Loading from cache
  - Installing symfony/polyfill-intl-idn (v1.17.1): Loading from cache
  - Installing symfony/proxy-manager-bridge (v3.4.42): Loading from cache
  - Installing symfony/security (v3.4.42): Loading from cache
  - Installing symfony/security-bundle (v3.4.42): Loading from cache
  - Installing symfony/serializer (v3.4.42): Loading from cache
  - Installing swiftmailer/swiftmailer (v6.2.3): Loading from cache
  - Installing symfony/swiftmailer-bundle (v3.3.1): Loading from cache
  - Installing symfony/templating (v3.4.42): Loading from cache
  - Installing symfony/validator (v3.4.42): Loading from cache
  - Installing symfony/web-server-bundle (v3.4.42): Loading from cache
  - Installing symfony/workflow (v3.4.42): Loading from cache
  - Installing twig/extensions (v1.5.4): Loading from cache
  - Installing vlucas/phpdotenv (v2.4.0): Loading from cache
  - Installing fzaninotto/faker (v1.9.0): Loading from cache
  - Installing bheller/images-generator (1.0.1): Loading from cache
  - Installing guzzlehttp/psr7 (1.6.1): Loading from cache
  - Installing guzzlehttp/guzzle (6.4.1): Loading from cache
  - Installing captbaritone/mailcatcher-codeception-module (1.2.1): Loading from cache
  - Installing symfony/dom-crawler (v3.4.42): Loading from cache
  - Installing symfony/css-selector (v3.4.42): Loading from cache
  - Installing symfony/browser-kit (v3.4.42): Loading from cache
  - Installing facebook/webdriver (1.7.1): Loading from cache
  - Installing sebastian/diff (2.0.1): Loading from cache
  - Installing sebastian/recursion-context (3.0.0): Loading from cache
  - Installing sebastian/exporter (3.1.2): Loading from cache
  - Installing sebastian/comparator (2.1.3): Loading from cache
  - Installing sebastian/version (2.0.1): Loading from cache
  - Installing sebastian/resource-operations (1.0.0): Loading from cache
  - Installing sebastian/object-reflector (1.1.1): Loading from cache
  - Installing sebastian/object-enumerator (3.0.3): Loading from cache
  - Installing sebastian/global-state (2.0.0): Loading from cache
  - Installing sebastian/environment (3.1.0): Loading from cache
  - Installing phpunit/php-text-template (1.2.1): Loading from cache
  - Installing phpunit/phpunit-mock-objects (5.0.10): Loading from cache
  - Installing phpunit/php-timer (1.0.9): Loading from cache
  - Installing phpunit/php-file-iterator (1.4.5): Loading from cache
  - Installing theseer/tokenizer (1.1.3): Loading from cache
  - Installing sebastian/code-unit-reverse-lookup (1.0.1): Loading from cache
  - Installing phpunit/php-token-stream (2.0.2): Loading from cache
  - Installing phpunit/php-code-coverage (5.3.2): Loading from cache
  - Installing webmozart/assert (1.6.0): Loading from cache
  - Installing phpdocumentor/reflection-common (2.0.0): Loading from cache
  - Installing phpdocumentor/type-resolver (1.0.1): Loading from cache
  - Installing phpdocumentor/reflection-docblock (4.3.2): Loading from cache
  - Installing phpspec/prophecy (1.9.0): Loading from cache
  - Installing phar-io/version (1.0.1): Loading from cache
  - Installing phar-io/manifest (1.0.1): Loading from cache
  - Installing myclabs/deep-copy (1.9.3): Loading from cache
  - Installing phpunit/phpunit (6.5.14): Loading from cache
  - Installing codeception/phpunit-wrapper (6.7.1): Loading from cache
  - Installing codeception/stub (2.1.0): Loading from cache
  - Installing behat/gherkin (v4.6.0): Loading from cache
  - Installing codeception/codeception (2.4.5): Loading from cache
  - Installing dama/doctrine-test-bundle (v5.0.5): Loading from cache
  - Installing easycorp/easy-log-handler (v1.0.9): Loading from cache
  - Installing mikey179/vfsstream (v1.6.8): Loading from cache
  - Installing php-coveralls/php-coveralls (v2.2.0): Loading from cache
  - Installing symfony/phpunit-bridge (v3.4.42): Loading from cache
Package zendframework/zend-eventmanager is abandoned, you should avoid using it. Use laminas/laminas-eventmanager instead.
Package zendframework/zend-code is abandoned, you should avoid using it. Use laminas/laminas-code instead.
Package sensio/generator-bundle is abandoned, you should avoid using it. Use symfony/maker-bundle instead.
Package setasign/fpdi-tcpdf is abandoned, you should avoid using it. No replacement was suggested.
Package facebook/webdriver is abandoned, you should avoid using it. Use php-webdriver/webdriver instead.
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Package easycorp/easy-log-handler is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
Deprecation Notice: Class Plugin\EntityExtension\Entity\CustomerSortNoTrait located in ./app/Plugin/EntityExtension/Entity/CustomerRankTrait.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201
Carbon 1 is deprecated, see how to migrate to Carbon 2.
https://carbon.nesbot.com/docs/#api-carbon-2
    You can run './vendor/bin/upgrade-carbon' to get help in updating carbon and other frameworks and libraries that depend on it.
55 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
ocramius/package-versions:  Generating version class...
ocramius/package-versions: ...done generating version class
Executing script cache:clear --no-warmup [OK]
Executing script cache:warmup --no-optional-warmers [OK]
Executing script assets:install --symlink --relative html [OK]

[ec2-user@ip-X-X-X-X ec-cube]$

EC-CUBEをインストールする
[ec2-user@ip-X-X-X-X ec-cube]$ bin/console eccube:install

EC-CUBE Installer Interactive Wizard
====================================

 If you prefer to not use this interactive wizard, define the environment valiables as follows:
 
  $ export APP_ENV=dev
  $ export APP_DEBUG=1
  $ export DATABASE_URL=database_url
  $ export DATABASE_SERVER_VERSION=server_version
  $ export MAILER_URL=mailer_url
  $ export ECCUBE_AUTH_MAGIC=auth_magic
  ... and more
  $ php bin/console eccube:install --no-interaction
 

 Database Url [sqlite:///var/eccube.db]:
 > mysql://ユーザー名:パスワード@RDSエンドポイント/空DB名

 Mailer Url [null://localhost]:
 > smtp://smtp.gmail.com:465   #Gmailを使用

 Auth Magic [gwhbP8glr6aVlDik]:
 >   #テストのため入力せず進む

 !                                                                                                                      
 ! [CAUTION] Execute the installation process. All data is initialized.                                                 
 !                                                                                                                      

 Is it OK? (yes/no) [yes]:
 > yes  #インストール最終確認OK

 Run doctrine:database:create --if-not-exists...
 Database `eccube4` for connection named default already exists. Skipped.

 Run doctrine:schema:drop --force...
 
 Dropping database schema...

 [OK] Database schema dropped successfully!                                     


 Run doctrine:schema:create...
 
 ! [CAUTION] This operation should not be executed in a production environment! 

 Creating database schema...

 [OK] Database schema created successfully!                                     


 Run eccube:fixtures:load...
   > Finished Successful!

 Run cache:clear --no-warmup...
 
 // Clearing the cache for the dev environment with debug                       
 // true                                                                        

 [OK] Cache for the "dev" environment (debug=true) was successfully cleared.    


                                                                                                                        
 [OK] EC-CUBE installation successful.                                                                                  
                                                                                                                        

[ec2-user@ip-X-X-X-X ec-cube]$

2. ブラウザでiPv4アドレス/ec-cube/ にアクセスする

3. ブラウザでiPv4アドレス/ec-cube/admin/ にアクセスする

EC-CUBE4.0.4のインストール完了です!
ログインID「admin」、パスワード「password」でログインできます。

ダミーデータ作成

1.      ec2-userのままコマンドを実行

ダミーデータ作成コマンドを実行する
[ec2-user@ip-X-X-X-X ec-cube]$ bin/console eccube:fixtures:generate
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO ...100
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO ...200
OOOOOOOOOOOOO16:05:03 WARNING   [translation] Translation not found. ["id" => "合計金額が不正です。","domain" => "messages","locale" => "ja"] ["file" => "/var/www/html/ec-cube/vendor/symfony/translation/LoggingTranslator.php","line" => 132,"class" => "Symfony\Component\Translation\LoggingTranslator","function" => "log","uid" => "c7430b8","user_id" => "N/A","session_id" => "N/A"]
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO ...300
(省略)
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO ...1000

eccube:fixtures:generate success
PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 2096104 bytes) in /var/www/html/ec-cube/vendor/easycorp/easy-log-handler/src/EasyLogFormatter.php on line 84
[ec2-user@ip-X-X-X-X ec-cube]$

バリデーションのエラーやメモリオーバーによるFatal Errorが発生してしまいましたが、
ある程度までは作成できました!
本来であれば会員データが100レコード、商品データが100レコード、注文データが1000レコード作成されるようです。

メモリ、256MBでは足りなかったみたいですね……。

実際に商品一覧ページを見てみると、すごいことになっていました。
これがランダム文字列による商品データです。
作成自体は出来ていることが確認できます。

バリデーションエラーの回避方法はまた後日として、
今回やりたかったことは概ね達成できました!

おわりに

これで、AWS環境にEC-CUBE4.0.4をインストールすることが出来ました。

上記の手順を確立させるまで寄り道回り道、エラーと戦ったり逃げたりしましたが、とても勉強になりました。
同じく困っている方がいらっしゃれば、少しでも参考になれば幸いです。

今度は寄り道回り道について、別でコラムを書きたいと思います!

以上、木下でした!

EC-CUBERでは、今回のようなTechブログの他にも、皆様のECビジネス成功をお助けする情報を随時更新していきます。
特に、弊社はEC-CUBEのプロフェッショナルですので、EC-CUBEのことなら、何でもご相談・お任せください!
▼問合せフォームから相談してみる。
https://ec-cuber.jp/contact-us/
▼電話で相談してみる。
03-6386-3652