LoginSignup
12
11

More than 5 years have passed since last update.

EC-CUBE3をnginx上にセットアップ CentOS7

Last updated at Posted at 2015-08-17

eccube3を動かすのに必要な基本的な手順を記述します。
実際に運用する場合ははSSL通したり、管理画面隠したり、いろいろとセキュリティ対策が必要になります。あくまで試用手順として参照ください。本投稿を参考にして生じたいかなる問題も当方では責任を負いかねます。

基本的なLAMP互換環境セットアップ

基本的にはこちら を参考に。

環境

  • CentOS7.1
  • nginx 1.6.3
  • MariaDB 5.5.41
  • PHP 5.4.16
  • eccube-3.0.2

epelリポジトリ有効化

頻繁に利用するので、epelリポジトリをセットアップしておきます。

console
$ sudo yum install epel-release

リポジトリ更新

最新にしておきます。

console
$ sudo yum update

SELinux 無効化

手順を簡易にするため、Permissiveにしておきます。

console
$ sudo setenforce 0

nginxのインストール

インストール

console
sudo yum install nginx

サービスの起動

インストールが完了したらサービスを実行します。
サービスを有効にして自動で起動するようにしておきます。

console
サービス有効化
$ sudo systemctl enable nginx
ln -s '/usr/lib/systemd/system/nginx.service' '/etc/systemd/system/multi-user.target.wants/nginx.service'

nginx起動
$ sudo systemctl start nginx

ステータス確認
$ sudo systemctl status nginx
nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled)
   Active: active (running) since Fri 2015-02-00 00:00:00 JST; 10s ago
  Process: 22314 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 22312 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
 Main PID: 22316 (nginx)
   CGroup: /system.slice/nginx.service
           ├─22316 nginx: master process /usr/sbin/nginx
           └─22317 nginx: worker process

Feb 00 00:00:00 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
Feb 00 00:00:00 localhost.localdomain nginx[22312]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Feb 00 00:00:00 localhost.localdomain nginx[22312]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Feb 00 00:00:00 localhost.localdomain systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
Feb 00 00:00:00 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.

ステータスがactive (running)になっているのを確認します。

Firewallポート開放

console
httpを常に開放
$ sudo firewall-cmd --add-service=http --permanent
success

設定リロード
$ sudo firewall-cmd --reload
success

動作確認
$ sudo firewall-cmd --list-service
dhcpv6-client http mysql ssh

httpが含まれていることを確認して下さい。

確認

nginxがstartedになっていたら、実際にhttpでアクセスしてみます。

console
$ curl localhost
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>Test Page for the Nginx HTTP Server on Fedora</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
(省略)

nginxのテストページのソースが返ってきます。ブラウザでも確認してみてください。

PHP(FastCGI)セットアップ

fastCGIとして動作するPHP-fpmをインストールします。
また、ec-cube3に必要なモジュールもインストールします。
詳しくはこちらを参考にしてください。

ec-cube ソフトウェア要件(3.0系)
※php-hashはmysqliの依存パッケージでインストールされます。

インストール

$ sudo yum install php-fpm php-mbstring php-mysqli php-mcrypt php-apc

サービス有効化
$ sudo systemctl enable php-fpm

起動
$ sudo systemctl start php-fpm

ステータス確認
$ sudo systemctl status php-fpm
php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled)
   Active: active (running) since 月 2015-08-17 21:45:15 JST; 7s ago
 Main PID: 22894 (php-fpm)
   Status: "Ready to handle connections"
   CGroup: /system.slice/php-fpm.service
           tq22894 php-fpm: master process (/etc/php-fpm.conf)
           tq22896 php-fpm: pool www
           tq22897 php-fpm: pool www
           tq22898 php-fpm: pool www
           tq22899 php-fpm: pool www
           mq22900 php-fpm: pool www

 8月 17 21:45:15 localhost.localdomain systemd[1]: Starting The PHP FastCGI ...
 8月 17 21:45:15 localhost.localdomain systemd[1]: Started The PHP FastCGI P...
Hint: Some lines were ellipsized, use -l to show in full.

設定ファイル編集

php.iniの設定

875行目あたりの[Date]でtimezoneをAsia/Tokyoに設定します。

console
$ sudo vi /etc/php.ini
/etc/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
; date.timezone =
date.timezone = "Asia/Tokyo"

www.conf の設定

console
$ sudo vi /etc/php-fpm.d/www.conf

proxyがapacheじゃなくてnginxなので、php-fpmのプロセスユーザーもnginxに変更しておきます。35行目あたりにプロセス関連の設定がありるので、userとgroupをapacheからnginxに変更します。

/etc/php-fpm.d/www.conf
; 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 Choosed to be able to access some dir as httpd
; user = apache
user = nginx
; RPM: Keep a group allowed to write in log dir.
; group = apache
group = nginx

restartして設定を反映します。

console
$ sudo systemctl restart php-fpm
$ sudo systemctl status php-fpm

ワーカープロセスのユーザーがnginxになっていることを確認します。

console
$ ps -ef | grep php
root     23063     1  0 22:21 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)
nginx    23065 23063  0 22:21 ?        00:00:00 php-fpm: pool www
nginx    23066 23063  0 22:21 ?        00:00:00 php-fpm: pool www
nginx    23067 23063  0 22:21 ?        00:00:00 php-fpm: pool www
nginx    23068 23063  0 22:21 ?        00:00:00 php-fpm: pool www
nginx    23069 23063  0 22:21 ?        00:00:00 php-fpm: pool www

セッションの保管場所

/var/lib/php/sessionディレクトリに保管されます。ディレクトリを作成して、所有者をnginxに変更します。

console
$ sudo mkdir /var/lib/php/session
$ sudo chown nginx:nginx /var/lib/php/session

MariaDB(MySQL互換)セットアップ

基本的にはMySQLと同じです。MariaDB5.5にてEC-Cube3動作確認しました。

インストール

console
$ sudo yum install mariadb mariadb-server

サービスの起動

console
サービス有効化
$ sudo systemctl enable mariadb
ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multiuser.target.wants/mariadb.service'

サービスの起動
$ sudo systemctl start mariadb
ステータス確認
mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled)
   Active: active (running) since 月 2015-08-17 20:10:36 JST; 6min ago
  Process: 15091 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 15063 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 15090 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           tq15090 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           mq15260 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysq...

 8月 17 20:10:34 localhost.localdomain systemd[1]: Starting MariaDB database...
 8月 17 20:10:34 localhost.localdomain mysqld_safe[15090]: 150817 20:10:34 m...
 8月 17 20:10:34 localhost.localdomain mysqld_safe[15090]: 150817 20:10:34 m...
 8月 17 20:10:36 localhost.localdomain systemd[1]: Started MariaDB database ...
Hint: Some lines were ellipsized, use -l to show in full.

ステータスがactive (running)になっているのを確認します。

DBのrootパスワード変更

rootが空パスワードなので、パスワード設定しておきます。

MariaDB
$ mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.41-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SET PASSWORD FOR root@localhost=PASSWORD('任意のパスワード');
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit;
Bye

確認
$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.41-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>exit;

EC-CUBE3セットアップ

ダウンロードと展開

console
$ cd ~
$ curl -O http://downloads.ec-cube.net/src/eccube-3.0.2.tar.gz
$ tar -xvf eccube-3.0.2.tar.gz

配置

配置場所は/var/lib/optなどが一般的です。今回は/var/libに配置します。

console
$ sudo mv ~/eccube-3.0.2 /var/lib

nginxのプロセスからアクセスするので、オーナーを変更します。

console
$ sudo chown -R nginx:nginx /var/lib/eccube-3.0.2/

nginx.conf

以下のように編集します。

/etc/nginx/nginx.conf
    server {
...中略...
        root         /var/lib/eccube-3.0.2/html
...中略...
# かならずこの順序でlocationを指定してください。install.phpがindex.phpに飛ばされてしまいます。
        location ~ \.php {
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;

        }

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

DB作成

データベース(スキーマ)とユーザーを作成して、アクセス権を与えます。

データベース名(スキーマ) eccube
ユーザー名 eccube_user
パスワード eccube_pass
console
$ mysql -u root -p

MariaDB [(none)]> create schema eccube;
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> grant all privileges on eccube.* to 'eccube_user'@'localhost' identified by 'eccube_pass';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit;

Web画面からセットアップ

トップ画面にアクセスすると、インストール画面へ飛ばされます。

http://yourhostname.com/

画面に従ってセットアップしてください。

12
11
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
12
11