eZ Publish 5.4 インストールガイド (RHSCL版)

## 概要
PHP 等のライブラリーのサポート期限を気にする環境のために、 Red Hat Software Collection (RHSCL) の CentOS 版の SCLo によるインストールを解説します。

## システム構成例
* CentOS 7.2.1511 (1610-01)
* Apache 2.4.18 (RHSCL)
* MySQL 5.6.26 (RHSCL)
* PHP 5.6.5 (RHSCL)

## 環境構築
### SCLo リポジトリの追加
```bash
yum -y install centos-release-scl-rh scl-utils
```

### Apache HTTP Server / PHP
#### Apache 2.4 / PHP 5.6 のインストール
```bash
yum -y install rh-php56{,-php{,-{gd,intl,mbstring,mysqlnd,opcache,process,xml}}}
```
#### PHP の設定
```bash
source scl_source enable rh-php56
echo -e '#!/bin/bash\nsource scl_source enable rh-php56' > /etc/profile.d/rh-php56.sh
ln -s /etc/{opt/rh/rh-php56/,}php.ini
sed -i.org 's|;date.timezone =|date.timezone = Asia/Tokyo|' /etc/php.ini
sed -i '/memory_limit/ s/128M/256M/' /etc/php.ini
```
#### Apache の設定
```bash
source scl_source enable httpd24
echo -e '#!/bin/bash\nsource scl_source enable httpd24' > /etc/profile.d/httpd24.sh
ln -s {/opt/rh/httpd24/root,}/etc/httpd
ln -s {/opt/rh/httpd24/root,}/var/www
ln -s /{usr/lib/systemd/system/httpd24-,etc/systemd/system/}httpd.service
systemctl daemon-reload
systemctl start httpd && systemctl enable $_
firewall-cmd --add-service=http{,s} --permanent && firewall-cmd --reload
```

### MySQL Community Server
#### MySQL 5.6 のインストール
```bash
yum install rh-mysql56-mysql-server
```
#### MySQL の設定
```bash
source scl_source enable rh-mysql56
echo -e '#!/bin/bash\nsource scl_source enable rh-mysql56' > /etc/profile.d/rh-mysql56.sh
ln -s /{usr/lib/systemd/system/rh-mysql56-,etc/systemd/system/}mysqld.service
systemctl daemon-reload
cat << "_EOF_" > /etc/my.cnf.d/ezpublish.cnf
character-set-server = utf8
innodb_buffer_pool_size = 128M
_EOF_
systemctl start mysqld && systemctl enable $_
mysql_secure_installation 
```

## eZ Publish
### データベースとDBユーザーの作成
```bash
cat << "_EOQ_" | mysql -u root -p
CREATE DATABASE `ezpublish` CHARACTER SET 'utf8';
CREATE USER 'ezpublish'@'localhost' IDENTIFIED BY 'ezpublish';
GRANT ALL ON ezpublish.* TO 'ezpublish'@'localhost';
_EOQ_
```
### ファイルの展開とパーミッションの設定
```bash
tar xf ezpublish5-5.4.0-ee-bul-full.tar.gz -C /opt/rh/httpd24/root/var/www
chown apache:apache -R /opt/rh/httpd24/root/var/www/ezpublish5/*
cd /opt/rh/httpd24/root/var/www/ezpublish5/
setfacl -R -m u:apache:rwx -m u:apache:rwx ezpublish/{cache,logs,config,sessions} ezpublish_legacy/{design,extension,settings,var} web
setfacl -dR -m u:apache:rwx -m u:apache:rwx ezpublish/{cache,logs,config,sessions} ezpublish_legacy/{design,extension,settings,var} web
chcon -R -t httpd_sys_script_rw_t ezpublish/{cache,logs,config,sessions} ezpublish_legacy/{design,extension,settings,var} web
```

### スワップ領域の作成
```bash
dd if=/dev/zero of=/var/tmp/swap bs=1M count=1024
mkswap /var/tmp/swap
chmod 600 /var/tmp/swap
swapon /var/tmp/swap
```

### Composer
https://doc.ez.no/display/EZP/Using+Composer
https://doc.ez.no/display/EZP/5.4.x+Update+Instructions

```bash
php -r "copy('https://getcomposer.org/download/1.0.3/composer.phar', 'composer.phar');"
php -d memory_limit=-1 composer.phar config http-basic.updates.ez.no <installation-key> <token-password>
php -d memory_limit=-1 composer.phar update --no-dev --prefer-dist --no-scripts ezsystems/ezpublish-legacy-installer
php -d memory_limit=-1 composer.phar selfupdate 
php -d memory_limit=-1 composer.phar remove --no-update --dev behat/mink-selenium-driver
php -d memory_limit=-1 composer.phar require --no-update symfony/symfony:~2.7.0 sensio/distribution-bundle:~3.0
php -d memory_limit=-1 composer.phar install --no-dev --prefer-dist
sed -i '/LegacyBundle;/i use eZ\\Bundle\\EzPublishLegacySearchEngineBundle\\EzPublishLegacySearchEngineBundle;' /opt/rh/httpd24/root/var/www/ezpublish5/ezpublish/EzPublishKernel.php
sed -i '/LegacyBundle(/i \            new EzPublishLegacySearchEngineBundle(),' /opt/rh/httpd24/root/var/www/ezpublish5/ezpublish/EzPublishKernel.php
```
### VirtualHost の設定
https://github.com/ezsystems/ezpublish-community/tree/master/doc/apache2

```
cp -a /opt/rh/httpd24/root/var/www/ezpublish5/doc/apache2/vhost.template /opt/rh/httpd24/root/etc/httpd/conf.d/ezpublish.conf
sed -i \
-e 's/%IP_ADDRESS%:%PORT%>/*:80>/' \
-e 's/ServerName %HOST%/ServerName www.example.com/' \
-e 's/ServerAlias %HOST_ALIAS%/ServerAlias localhost/' \
-e 's/%BASEDIR%\/web/\/opt\/rh\/httpd24\/root\/var\/www\/ezpublish5\/web/' \
-e 's/=%ENV%/=dev/' /opt/rh/httpd24/root/etc/httpd/conf.d/ezpublish.conf
```