EC-CUBE 4.0のテスト環境が必要になったので、Oracle Cloud上のOracle Linux 7インスタンスを立てて、その上に作成した。
が・・・公式ドキュメントはSELinux関連の設定とか触れてないし、かなり面倒だった。
環境初期準備
タイムゾーンを日本に設定
# timedatectl set-timezone Japan
fail2ban設定
sshアタックがあった場合にとっととIPバンするためにfail2banをインストール
# yum install -y fail2ban fail2ban-hostsdeny fail2ban-systemd # systemctl enable fail2ban.service # cat <<EOF > /etc/fail2ban/jail.local [DEFAULT] # 24時間以内に3回不審なアクセスがあったら24時間BAN #bantime = 86400 #findtime = 86400 bantime = 259200 findtime = 259200 maxretry = 5 #CentOS7なのでsystemd #backend = systemd # jail.d/00-systemd.conf で設定されてた # 除外IP ignoreip = 127.0.0.1 127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 <除外したいIPを追加> [sshd] enabled = true banaction = firewallcmd-ipset EOF # systemctl start fail2ban.service #
webサーバとphp設定
phpはOracleが用意しているphp 7.2を使用するため、「oracle-php-release-el7」をインストール。現状の標準設定だとphp 7.2が標準選択されている。なお、php 7.1かphp 7.0を使うこともできるが、いまさら利点は無いので使用しない方がよい。
# yum install oracle-php-release-el7 #
phpパッケージとhttpdをインストールして、firewall開け設定実施
# yum install -y httpd mod_ssl php php-json php-mbstring php-pdo php-xml php-zip php-mysqlnd php-intl # systemctl enable httpd # systemctl start httpd # firewall-cmd --permanent --zone=public --add-service=http # firewall-cmd --permanent --zone=public --add-service=https # firewall-cmd --reload
APCU(php-pecl-apcu)のインストールを推奨されたが、パッケージのコンフリクトが発生していたのでインストールしなかった。
SQLサーバ設定
今回はmariadbをSQLサーバとして使用した。
# yum install -y mariadb-server # systemctl enable mariadb # systemctl start mariadb #
また、ECCUBE用のデータベースを作成した。
# mysql -u root Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.64-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database eccube character set utf8; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all on eccube.* to cubesql@localhost identified by 'dbsqlp@ss'; Query OK, 0 rows affected (0.08 sec) MariaDB [(none)]> exit Bye #
ECCUBEファイル展開
/var/www/html/eccube にEC-CUBE 4.0.3を展開した。
展開した中に.htaccessファイルが含まれていますが、標準設定では読み込まないのでApacheに設定追加を行います。 (もっとセキュリティを強化してもいいとは思いますが、面倒だったので・・・)
# cat <<EOF> /etc/httpd/conf.d/eccube.conf <Directory "/var/www/html/eccube"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> EOF # systemctl restart httpd #
で・・・SELinuxがらみがどうなるかですが、おもいっきり引っかかりまくりました。
とりあえず該当するコンテンツに対して「httpd_sys_rw_content_t」を割り当てることで対処しました。
最初は個別に対処していこうとしたのですが、インストールプロセスを進めていくと、/var/www/html/eccube全体に対して権限を要求されたため、最終的には下記となりました。
# chcon -t httpd_sys_rw_content_t -R /var/www/html/eccube #
とりあえず、これでEC-CUBE 4.0の初期セットアップ完了までできるようになりました。
エラーコレクション
SELinux設定をしていく中で出てきたエラー群です。
まず、 http://IPアドレス/eccube/ にアクセスすると以下が現れました。
(2/2) ContextErrorException Warning: file_put_contents(/var/www/html/eccube/var/cache/install/EccubeInstallDebugProjectContainerDeprecations.log): failed to open stream: No such file or directory (1/2) RuntimeException Unable to create the cache directory (/var/www/html/eccube/var/cache/install)
このときに表示された /var/www/html/eccube/var に対して「chcon -t httpd_sys_rw_content_t -R /var/www/html/eccube/var」を実行しました。
次にでたエラーは下記です。
Filesystem->copy('/var/www/html/eccube/html/template/default/assets/img/common/favicon.ico', '/var/www/html/eccube/html/user_data/assets/img/common/favicon.ico')
/var/www/html/eccube/html/user_data以下に書き込む権限がないというもの。
eccubeディレクトリ内を探すと他にも「user_data」というディレクトリがあったため、「chcon -t httpd_sys_rw_content_t -R /var/www/html/eccube/html/user_data」と「chcon -t httpd_sys_rw_content_t -R /var/www/html/eccube/app/template/user_data」を実行した。
最後に「権限チェック」で引っかかった。
以下のファイルまたはディレクトリに書き込み権限を付与してください。 >>☓:/var/www/html/eccube >>☓:/var/www/html/eccube/app/Plugin >>☓:/var/www/html/eccube/app/PluginData >>☓:/var/www/html/eccube/app/proxy >>☓:/var/www/html/eccube/app/template >>☓:/var/www/html/eccube/html >>☓:/var/www/html/eccube/vendor <略> >>☓:/var/www/html/eccube/vendor/ocramius/proxy-manager/README.md >>☓:/var/www/html/eccube/vendor/ocramius/proxy-manager/composer.json >>☓:/var/www/html/eccube/composer.json >>☓:/var/www/html/eccube/composer.lock
ようはここまでで「httpd_sys_rw_content_t」を設定しなかった全ファイル。
「chcon -t httpd_sys_rw_content_t -R /var/www/html/eccube」を実行して再チェック・・・
>>○:アクセス権限は正常です
これでセットアップを進めることができました。