takafumi blog

日々の勉強メモ

CentOS7にPHP5.6をソースからインストール

環境   CentOS 7.0 PHP 5.6

ちょっとpthreadsを使ってみたかったので、phpをソースからインストールする。

php最新版インストール
2015/03/10では5.6

$ yum install libxml2 libxml2-devel

$ wget "http://jp1.php.net/get/php-5.6.6.tar.bz2/from/this/mirror" -O php-5.6.6.tar.bz2
$ tar xjvf php-5.6.6.tar.bz2
$ cd php-5.6.6

$ make clean; make distclean

# pthreadを使えるように設定する。
# --enable-maintainer-zts を設定

# phpdbgを使えるようにする
# --enable-phpdbg を設定

# apacheのモジュールとして組み込めるようにする。libphp5.soを生成。
# --with-apxs2 を設定
./configure \
  --with-config-file-path=/etc           \
  --with-config-file-scan-dir=/etc/php.d \
  --enable-maintainer-zts                \
  --with-pear                            \
  --with-mcrypt                          \
  --with-zlib                            \
  --enable-mbstring                      \
  --with-curl                            \
  --with-bz2                             \
  --enable-zip                           \
  --enable-sockets                       \
  --enable-sysvsem                       \
  --enable-sysvshm                       \
  --with-mhash                           \
  --with-pcre-regex                      \
  --enable-bcmath                        \
  --with-openssl                         \
  --enable-pcntl                         \
  --enable-modules=so

エラーが出たら対応して、再度configureする。

configure: error: Cannot find OpenSSL's <evp.h>
$ yum install openssl-devel
configure: error: Please reinstall the BZip2 distribution
$ yum install bzip2-devel 


configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/
$ yum insatll curl-devel


configure: error: mcrypt.h not found. Please reinstall libmcrypt.
$ yum install libmcrypt-devel --enablerepo=epel



再度configureし、成功したら

$ make test
$ make 
$ make install;
$ php -v
PHP 5.6.6 (cli) (built: Mar 12 2015 07:49:59)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

ちなみに、make testでエラーが出たけど無視した。
そのせいかmake uninstallが効かないが、インストールログをとっておいて、インストールしたものを削除すればOK。

php.iniを作成

$ cp -a php.ini-development /etc/php.ini
$ mkdir -p /etc/php.d

バージョンを確認

$ php -v

PHP 5.6.6 (cli) (built: Mar 13 2015 08:31:20)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

php.iniがちゃんと読み込まれているか確認

$ php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed:      (none)

OK。

【参考】
PHP: 中心となる configure オプションのリスト - Manual
phpのconfigureオプションとインストールに必要なyumのパッケージ | 本日も乙