経緯

ECCUBEを利用しているサーバーでペイジェントモジュールを利用していたところ、ペイジェントより、12月からモジュールサーバーのSHA2対応をするという通知が送られてきました。

素のCentOS6系でyumでPHPやらOpenSSLをインストールしている場合は、ペイジェントモジュールの証明書ファイルの差し替えのみでOKのようですが、CentOS5系でOpenSSLやPHPをyumでインストールした場合はソースからコンパイルが必要になります。

理由としては、CentOS5系のPHPにはすでにOpenSSLのモジュールが組み込まれており、yumでインストールされたOpenSSLをいくらアップデートしても、PHPの方には影響が無いという理由があります。

また、OpenSSLはCentOS5系の標準だと、openssl-0.9.8eまでしかアップデートできません。

なお、openssl-0.9.8e-18で下記のような記述がありますが、

* Thu Mar 10 2011 Tomas Mraz <tmraz@redhat.com> 0.9.8e-18
  - add SHA-2 hashes in SSL_library_init() (#676384)

デフォルトでは有効ではないようで、sha2がデフォルトで使用できるようになっているのはopenssl-0.9.8o以降からのようです。

なので、OpenSSLを0.9.8o以降でコンパイルし、それを指定する形でPHPもコンパイルが必要です。

その手順を下記に記載しますので、参考になると嬉しいです。

※慣れていない場合はVagrantなどを活用して、何度か手順を確認しつつ、ご自身のサーバーに合った方法に書き換えていただけると良いかと思います。

バックアップ

# cd /etc/
# cp -p php.ini php.ini.`date +%Y%m%d`

# cp -rp php.d php.d.`date +%Y%m%d`

# cp -rp /usr /usr.`date +%Y%m%d`

事前にインストール

# yum install bzip2* libcurl* curl-devel pcre* db4-devel libjpeg* libpng* freetype* gmp* libc-client-devel openldap-devel mysql-devel ncurses-devel unixODBC-devel postgresql-devel sqlite-devel aspell-devel libxslt libxslt-devel net-snmp net-snmp-devel flex krb5-devel httpd-devel

※httpd-develがないとPHPのコンパイル時にapxsが無いと言われます。

srcダウンロード
wget http://www.openssl.org/source/openssl-0.9.8zg.tar.gz
wget http://museum.php.net/php5/php-5.1.6.tar.gz

※Vagrantを使用している場合はここでvagrant sandbox on。

OpenSSLのビルド
# ./config –prefix=/usr/local/openssl shared zlib
# make
# make install

# cp /usr/lib64/mysql/libmysqlclient* /usr/lib64/

※ここはコピーよりもシンボリックリンクの方が良いかもしれません。

PHPのビルド
./configure \
–prefix=/usr/local/php \
–with-apxs2=/usr/sbin/apxs \
–with-config-file-scan-dir=/usr/local/php/etc/php.d \
–with-pic \
–disable-rpath \
–with-bz2 \
–with-curl \
–with-freetype \
–with-png \
–enable-gd-native-ttf \
–without-gdbm \
–with-gettext \
–with-gmp \
–with-iconv \
–with-jpeg \
–with-png \
–with-pspell \
–with-expat \
–with-pcre-regex \
–with-zlib \
–with-layout=GNU \
–enable-exif \
–enable-ftp \
–enable-magic-quotes \
–enable-sockets \
–enable-sysvsem \
–enable-sysvshm \
–enable-sysvmsg \
–enable-track-vars \
–enable-trans-sid \
–enable-yp \
–enable-wddx \
–enable-ucd-snmp-hack \
–with-unixODBC=shared,/usr \
–with-ODBC \
–enable-memory-limit \
–enable-shmop \
–enable-calendar \
–enable-dbx \
–enable-dio \
–with-mime-magic=/usr/share/file/magic.mime \
–without-sqlite \
–with-xml \
–with-libxml \
–with-system-tzdata \
–enable-pcntl \
–with-imap=shared \
–with-imap-ssl \
–enable-mbstring=shared \
–enable-mbstr-enc-trans \
–enable-mbregex \
–with-ncurses=shared \
–with-gd=shared \
–enable-bcmath=shared \
–enable-dba=shared \
–with-db4 \
–with-xmlrpc=shared \
–with-ldap=shared \
–with-ldap-sasl \
–with-mysql=shared \
–with-mysqli=shared,/usr/lib64/mysql/mysql_config \
–enable-dom=shared \
–with-dom-xslt \
–with-dom-exslt \
–with-pgsql=shared \
–with-snmp=shared \
–enable-soap=shared \
–with-xsl=shared \
–enable-xmlreader=shared \
–enable-xmlwriter=shared \
–enable-pdo=shared \
–with-pdo-odbc=shared,unixODBC,/usr \
–with-pdo-mysql=shared,/usr/lib64/mysql/mysql_config \
–with-pdo-pgsql=shared \
–with-pdo-sqlite=shared \
–enable-dbase=shared \
–with-kerberos \
–with-openssl=/usr/local/openssl \
–without-pear

# make
# make install

パスを通す

# export LD_LIBRARY_PATH=/usr/local/openssl/lib/
# vi etc/ld.so.conf.d/openssl.conf
/usr/local/openssl/lib/
# ldconfig

http://qiita.com/HirokiTakaba/items/0ec56590aee83aa371d4

iniファイルのコピー

※PHPのコンパイルオプションで「–with-config-file-scan-dir=/usr/local/php/etc/php.d」を指定しなかった場合は不要です。よくわからない場合はどこを参照しているかをphpinfoで確認されることをおすすめします。

# cd /usr/local/php/etc/php.d/
# cp -p /etc/php.d/* .

Apacheの再起動

# service httpd configtest

# service httpd restart

# pgrep -fl httpd

※プロセスが稼働していること確認。

 

 

まとめ

ソースコンパイルに慣れている場合や、元々ソースからインストールしている場合などはそこまで大変ではありませんが、yumで管理しているサーバーだったり、ソースコンパイルに慣れていない場合は最初はかなり大変かと思います。

出来る限りテストサーバーを立てて、自分のサーバーにあった手順を繰り返し確認されることをおすすめいたします。

 

以上。