ECCUBE4をローカル環境にインストールしてみた

# はじめに
自作テンプレートの開発のため、ECCUBEをローカル環境に構築しようと思いググってみると、
XAMPPやMAMP環境にインストールしている記事が多く見られました。
ですが、今回はそれらの外に環境を構築してみたいと思います。
3系は下記のコマンドで一発でインストールできたのですが、4系ではエラー。。

```c

## Windows
export ECCUBE_VERSION=4.0.2 && curl "http://downloads.ec-cube.net/src/eccube-${ECCUBE_VERSION}.tar.gz" | tar xvzf - && cd "eccube-${ECCUBE_VERSION}" && php eccube_install.php sqlite3 none && php -S localhost:8080 -t html html/index.php
```

で、最後に

```
Could not open input file: eccube_install.php
```

ほう...なのでコマンドを打ちます

```
cd eccube-4.0.2
php bin/console eccube:install
```
すると今度は

```
 [WARNING] Some commands could not be registered:                              
                                                                               

In AbstractSQLiteDriver.php line 43:
                                                                               
  An exception occurred while executing 'SELECT t0.id AS id_1, t0.company_name AS company_name_2, t0.company_kana AS
  company_kana_3, t0.postal_code AS postal_code_4, t0.addr01 AS addr01_5, t0.addr02 AS addr02_6, t0.phone_number AS p
  hone_number_7, t0.business_hour AS business_hour_8, t0.email01 AS email01_9, t0.email02 AS email02_10, t0.email03 A
  S email03_11, t0.email04 AS email04_12, t0.shop_name AS shop_name_13, t0.shop_kana AS shop_kana_14, t0.shop_name_en
  g AS shop_name_eng_15, t0.update_date AS update_date_16, t0.good_traded AS good_traded_17, t0.message AS message_18
  , t0.delivery_free_amount AS delivery_free_amount_19, t0.delivery_free_quantity AS delivery_free_quantity_20, t0.op
  tion_mypage_order_status_display AS option_mypage_order_status_display_21, t0.option_nostock_hidden AS option_nosto
  ck_hidden_22, t0.option_favorite_product AS option_favorite_product_23, t0.option_product_delivery_fee AS option_pr
  oduct_delivery_fee_24, t0.option_product_tax_rule AS option_product_tax_rule_25, t0.option_customer_activate AS opt
  ion_customer_activate_26, t0.option_remember_me AS option_remember_me_27, t0.authentication_key AS authentication_k
  ey_28, t0.php_path AS php_path_29, t0.option_point AS option_point_30, t0.basic_point_rate AS basic_point_rate_31,
  t0.point_conversion_rate AS point_conversion_rate_32, t0.country_id AS country_id_33, t0.pref_id AS pref_id_34, t0.
  discriminator_type FROM dtb_base_info t0 WHERE t0.id = ? AND t0.discriminator_type IN ('baseinfo')' with params [1]
  :                                                                            
                                                                               
  SQLSTATE[HY000]: General error: 1 no such table: dtb_base_info               
                                                                               

In PDOConnection.php line 63:

  SQLSTATE[HY000]: General error: 1 no such table: dtb_base_info


In PDOConnection.php line 61:

  SQLSTATE[HY000]: General error: 1 no such table: dtb_base_info



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

```

意味が分からん...
もう知らん！

```
php bin/console server:run
```

```
 [WARNING] Some commands could not be registered:


In AbstractSQLiteDriver.php line 43:

  An exception occurred while executing 'SELECT t0.id AS id_1, t0.company_nam
  e AS company_name_2, t0.company_kana AS company_kana_3, t0.postal_code AS p
  ostal_code_4, t0.addr01 AS addr01_5, t0.addr02 AS addr02_6, t0.phone_number
   AS phone_number_7, t0.business_hour AS business_hour_8, t0.email01 AS emai
  l01_9, t0.email02 AS email02_10, t0.email03 AS email03_11, t0.email04 AS em
  ail04_12, t0.shop_name AS shop_name_13, t0.shop_kana AS shop_kana_14, t0.sh
  op_name_eng AS shop_name_eng_15, t0.update_date AS update_date_16, t0.good_
  traded AS good_traded_17, t0.message AS message_18, t0.delivery_free_amount
   AS delivery_free_amount_19, t0.delivery_free_quantity AS delivery_free_qua
  ntity_20, t0.option_mypage_order_status_display AS option_mypage_order_stat
  us_display_21, t0.option_nostock_hidden AS option_nostock_hidden_22, t0.opt
  ion_favorite_product AS option_favorite_product_23, t0.option_product_deliv
  ery_fee AS option_product_delivery_fee_24, t0.option_product_tax_rule AS op
  tion_product_tax_rule_25, t0.option_customer_activate AS option_customer_ac
  tivate_26, t0.option_remember_me AS option_remember_me_27, t0.authenticatio
  n_key AS authentication_key_28, t0.php_path AS php_path_29, t0.option_point
   AS option_point_30, t0.basic_point_rate AS basic_point_rate_31, t0.point_c
  onversion_rate AS point_conversion_rate_32, t0.country_id AS country_id_33,
   t0.pref_id AS pref_id_34, t0.discriminator_type FROM dtb_base_info t0 WHER
  E t0.id = ? AND t0.discriminator_type IN ('baseinfo')' with params [1]:

  SQLSTATE[HY000]: General error: 1 no such table: dtb_base_info


In PDOConnection.php line 63:

  SQLSTATE[HY000]: General error: 1 no such table: dtb_base_info


In PDOConnection.php line 61:

  SQLSTATE[HY000]: General error: 1 no such table: dtb_base_info




 [OK] Server listening on http://127.0.0.1:8000

```

ん、何か色々怒られてるけどサーバー起動したっぽい
仕方ないのでlocalhost:8000にアクセスしてWebインストーラーでインストール。

途中でintlを有効化しろ！って怒られたけど一応成功。

でも再度サーバーを起動するときにコマンドが通らない

```
 There are no commands defined in the "server" namespace.
```

この場合は.envを以下のように編集

```
APP_ENV=prod
　　　↓
APP_ENV=dev
```

無事にサーバーが起動しました。

# Composerをインストール

https://getcomposer.org/download/

# PHPをインストール

https://windows.php.net/qa/

解凍ファイルをCドライブ直下に保存

```
C:\php-7.2.2\
```

先に環境変数を通します

[コントロールパネル]→[システムとセキュリティ]→[システム]→[システムの詳細設定]→[環境変数]

次にphp.ini-developmentを複製してphp.iniを作成します。

以下の箇所を編集します。
行頭のセミコロンを外して有効化していきます。

```php.ini
## 750~760行
extension_dir = "./"
; On windows:
extension_dir = "ext"

## 880~945行目
extension=fileinfo
extension=curl
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
extension=pdo_pgsql
extension=pdo_sqlite


extension=sockets
extension=sqlite3

## 954~957行目
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Tokyo

```

再度のコマンドでインストールできているか確認

```
php -v
```

# Apacheをインストール

https://httpd.apache.org/download.cgi

管理者権限でコマンドを起動して以下を実行

```c

C:/Apache24/bin>httpd -k install

## 環境変数を通しておくとこれだけ
httpd -k install

```

次にhttpd.confの最終行に以下を記述

```httpd.conf
LoadModule php7_module "c:/php-7.2.2/php7apache2_4.dll"
Loadfile "c:/php-7.2.2/php7ts.dll"
Loadfile "c:/php-7.2.2/libpq.dll"
PHPIniDir "c:/php-7.2.2"
AddHandler php7-script .php
AddType application/x-httpd-php .php
AddType application/xhttpd-php-source .phps
```


# ECCUBEをインストール

参考：
http://doc4.ec-cube.net/quickstart_install

```
php composer.phar create-project ec-cube/ec-cube ec-cube "4.0.x-dev" --keep-vcs

# または

composer create-project ec-cube/ec-cube ec-cube "4.0.x-dev" --keep-vcs

```

しかし、これがエラーが出てインストール停止するので、
最終的には以下の方法でWebインストーラー経由でセットアップしました。

```
composer create-project --no-scripts ec-cube/ec-cube ec-cube "4.0.x-dev" --keep-vcs
```

ローカルだと結構時間がかかるのですが、デフォルトだと30秒でタイムアウトします。

```php.ini
## 377行目付近

max_execution_time = 600

max_input_time = 600

## 846行目付近
default_socket_timeout = 600

```

## upload_max_filesizeを設定

自作のテンプレートを管理画面からアップロードしようとしたのですが、
ファイル容量がオーバーしているせいでエラーを吐いたので設定。

```php.ini

post_max_size = 64M
 
upload_max_filesize = 64M

```

```[.htaccess]
php_value upload_max_filesize 64M
```

# 感想
今まではLAMP環境の構築はXAMPPに頼っていたので思いのほか苦戦しました。
次はVirtualBoxやVagrant,Dockerに挑戦してみようと思います。