LoginSignup
3
2

More than 1 year has passed since last update.

eccube4+nginx+AmazonLinux2で構築してみた。

Last updated at Posted at 2021-05-10

aws研修の一環で作成することになりましたので、メモ書きがわりに残しておきます。

Eccube4のシステム要件ではApacheが推奨でありますが、研修ではnginxで作成する方針になりました。
世の中的にはnginxの方がシェア拡大中でありますので、こちらで作成した方が良いとの判断なのでしょうね。
ECCUBE4システム要件参考

スクリーンショット 2021-05-10 12.56.22.png

インストール

eccube4に必要なパッケージをインストールしていきます。

phpインストール

[ec2-user@ip-10-2-0-227 ~]$ sudo yum -y install php74 php74-php
・・・略・・・
[ec2-user@ip-10-2-0-227 ~]$ php -v
PHP 7.4.19 (cli) (built: May  4 2021 11:06:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.19, Copyright (c), by Zend Technologies

composerインストール

以下にアクセスし、4行のコマンドを実行
https://getcomposer.org/download/

[root@ip-10-2-0-227 ~]# composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.0.13 2021-04-27 13:11:08

nginx インストール

[ec2-user@ip-10-2-0-227 ~]$ sudo yum install -y nginx
・・・略・・・
[ec2-user@ip-10-2-0-227 ~]$ nginx -v
nginx version: nginx/1.16.1

私はApacheで作成テストしたのち、nginxに移行したので、競合しないための処置を行う。

[ec2-user@ip-10-2-0-227 ~]$ sudo systemctl stop httpd
[ec2-user@ip-10-2-0-227 ~]$ sudo systemctl start nginx
[ec2-user@ip-10-2-0-227 ~]$ sudo systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[ec2-user@ip-10-2-0-227 ~]$ sudo systemctl disable httpd
Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.

php-fpm インストール

どうやらnginxを使う際にはphp-fpmなるものが必要らしいのでこれをインストール
ただ、当環境において普通にインストールするとphp-fpmのversionは5系となってしまう。
これでは、phpのversionとのずれ、及びeccubeのシステム要件と一致しないため注意。
(これに気づかず1時間取られた。)
php-fpm詳細

[ec2-user@ip-10-2-0-227 ~]$ sudo yum install -y php74-php-fpm
・・・略・・・
[ec2-user@ip-10-2-0-227 ~]$ sudo cp /etc/opt/remi/php74/php-fpm.d/www.conf /etc/opt/remi/php74/php-fpm.d/www.conf.org
[ec2-user@ip-10-2-0-227 ~]$ sudo vi /etc/opt/remi/php74/php-fpm.d/www.conf
[ec2-user@ip-10-2-0-227 ~]$ sudo systemctl start php74-php-fpm
[ec2-user@ip-10-2-0-227 ~]$ sudo systemctl enable php74-php-fpm

/etc/opt/remi/php74/php-fpm.d/www.conf は以下のように編集してください。
詳細
userやgroupに指定するのもはwww-dataなども挙げられますが、nginxの記述によります。
詳しくはnginxの設定で述べます。

/etc/opt/remi/php74/php-fpm.d/www.conf
user = nginx
group = nginx

eccube4 インストール

[ec2-user@ip-10-2-0-227 ~]$ pwd
/home/ec2-user/
[ec2-user@ip-10-2-0-227 ~]$ unzip eccube-4.0.5.zip
[ec2-user@ip-10-2-0-227 ~]$ mv eccube-4.0.5 eccube
[ec2-user@ip-10-2-0-227 ~]$ sudo chown nginx:nginx eccube
[ec2-user@ip-10-2-0-227 ~]$ sudo chmod -R o+x eccube
[ec2-user@ip-10-2-0-227 ~]$ ls -l
合計 42796
drwxrwxrwx 11 nginx    nginx        4096  5月 10 03:43 eccube
-rw-r--r-x  1 ec2-user ec2-user 43804031  5月  6 03:21 eccube-4.0.5.zip

とりあえずインストールは終わりです。

nginx設定

[ec2-user@ip-10-2-0-227 ~]$ sudo vi /etc/nginx/nginx.conf
[ec2-user@ip-10-2-0-227 ~]$ sudo systemctl restart nginx
/etc/nginx/nginx.conf
user nginx;

5行目くらいにuserがあります。
これでnginx(webサーバを実行するユーザを指定します。)

以下変更部

/etc/nginx/nginx.conf

    server {
    listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /home/ec2-user/eccube/;
        access_log /var/log/nginx/eccube.log;
        error_log /var/log/nginx/eccube.error.log;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
                index index.php index.html;
                try_files $uri $uri/ /index.php;
        }

    error_page 404 /404.html;
        location = /404.html {
        }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }

        location ~ install\.php\/.+$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            include fastcgi_params;
            try_files $uri $uri/ /install.php;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            include fastcgi_params;
            try_files $uri =404;
        }
    }

以上で、無事eccubeが構築できたかと思います。

メモ書き

curl

webブラウザが正常に動いているかどうかは、

$ curl http://localhost/

いちいちwebブラウザ開かなくてもこれで確認するのが早いです。

40x系、50x系エラーの対処

何が起こっているかはちゃんとエラーログに載ってるので、これをみましょう。
同じコマンドを何回も打つとかやりがちですけど、無駄なので。

$ sudo cat /var/log/nginx/eccube.error.log

ここからは私が遭遇したエラーログです。

Permission denied系

eccubeのPATHや、権限周りを確認してください。
eccube4 インストールで述べたchown,chmod周り、PATH関係を確認してください。

FastCGI sent in stderr: "PHP message: PHP Parse error:

php-fpmのversionが5系が入っている可能性が高いです。
php-fpm インストールで述べたあたりを参考にしてください。

phpのページがダウンロードされてしまう。

php-fpmが正常に実行されていない可能性が高いです。

$  sudo systemctl status php74-php-fpm.service
● php74-php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php74-php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since 月 2021-05-10 03:21:36 UTC; 1h 58min ago

Activeがactiveになっていることを確認してください。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2