LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

【途中】VirtualBox->CentOS7にphpenv + php-buildでPHPを複数バージョン利用する

Last updated at Posted at 2015-08-31

準備Ⅰ. 仮想サーバーの用意

  • VirtualBox4.3.28
  • CentOS7

--> 問題なくインストールおよび設定ができました。

準備Ⅱ. 仮想サーバーの環境構築

目次
0. 各種コマンドのインストール
1. yumリポジトリ追加
2. ビルド環境構築
3. 依存パッケージインストール
4. Apache-2.2.31 をインストール
5. bisonの Ver. 2.4.1 を localへインストール
6. re2cをインストール
7. libevent-1.4-15をインストール
8. libmcrypt-2.5.7をインストール

0. 各種コマンドのインストール

-->この後の環境構築で利用するコマンド(wget, git, patch, ...)をインストール

実行コマンド
$ sudo yum install wget
$ sudo yum install git
$ sudo yum install patch

1. yumリポジトリ追加

CentOSの標準リポジトリに含まれていないパッケージが必要になることがあるので、
サードパーティーリポジトリの追加を行う。
サードパーティーリポジトリの優先順位は、EPEL → RepoForge(旧RPMForge)の順に設定。

実行コマンド
$ sudo yum -y install yum-priorities
$ sudo vim /etc/yum.repos.d/CentOS-Base.repo
CentOS-Base.repo(ファイル内追記)
...

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
priority=1
^^^^^^^^^^ 追記

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
priority=1
^^^^^^^^^^ 追記

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
priority=1
^^^^^^^^^^ 追記

#additional packages that extend functionality of existing packages
[centosplus]

...

2.ビルド環境構築

この後ビルド(インストール->動作設定)するApache HTTP サーバの
コンパイル・インストールに必要なモジュール等を用意

実行コマンド
$ sudo yum install autoconf automake libtool.x86_64 flex.x86_64 bison.x86_64 gcc.x86_64 gcc-c++.x86_64 make.x86_64 kernel-headers.x86_64 kernel-devel.x86_64
$ 
(実行結果)
インストール:
  autoconf.noarch 0:2.69-11.el7                       automake.noarch 0:1.13.4-3.el7
  bison.x86_64 0:2.7-4.el7                            flex.x86_64 0:2.5.37-3.el7
  gcc.x86_64 0:4.8.3-9.el7                            gcc-c++.x86_64 0:4.8.3-9.el7
  kernel-devel.x86_64 0:3.10.0-229.11.1.el7           kernel-headers.x86_64 0:3.10.0-229.11.1.el7
  libtool.x86_64 0:2.4.2-20.el7                      

依存性関連をインストールしました:
  cpp.x86_64 0:4.8.3-9.el7                                 glibc-devel.x86_64 0:2.17-78.el7
  glibc-headers.x86_64 0:2.17-78.el7                       libmpc.x86_64 0:1.0.1-3.el7
  libstdc++-devel.x86_64 0:4.8.3-9.el7                     m4.x86_64 0:1.4.16-9.el7
  mpfr.x86_64 0:3.1.1-4.el7                                perl.x86_64 4:5.16.3-285.el7
  perl-Carp.noarch 0:1.26-244.el7                          perl-Data-Dumper.x86_64 0:2.145-3.el7
  perl-Encode.x86_64 0:2.51-7.el7                          perl-Exporter.noarch 0:5.68-3.el7
  perl-File-Path.noarch 0:2.09-2.el7                       perl-File-Temp.noarch 0:0.23.01-3.el7
  perl-Filter.x86_64 0:1.49-3.el7                          perl-Getopt-Long.noarch 0:2.40-2.el7
  perl-HTTP-Tiny.noarch 0:0.033-3.el7                      perl-PathTools.x86_64 0:3.40-5.el7
  perl-Pod-Escapes.noarch 1:1.04-285.el7                   perl-Pod-Perldoc.noarch 0:3.20-4.el7
  perl-Pod-Simple.noarch 1:3.28-4.el7                      perl-Pod-Usage.noarch 0:1.63-3.el7
  perl-Scalar-List-Utils.x86_64 0:1.27-248.el7             perl-Socket.x86_64 0:2.010-3.el7
  perl-Storable.x86_64 0:2.45-3.el7                        perl-Test-Harness.noarch 0:3.28-2.el7
  perl-Text-ParseWords.noarch 0:3.29-4.el7                 perl-Thread-Queue.noarch 0:3.02-2.el7
  perl-Time-HiRes.x86_64 4:1.9725-3.el7                    perl-Time-Local.noarch 0:1.2300-2.el7
  perl-constant.noarch 0:1.27-2.el7                        perl-libs.x86_64 4:5.16.3-285.el7
  perl-macros.x86_64 4:5.16.3-285.el7                      perl-parent.noarch 1:0.225-244.el7
  perl-podlators.noarch 0:2.5.1-3.el7                      perl-threads.x86_64 0:1.87-4.el7
  perl-threads-shared.x86_64 0:1.43-6.el7                 

完了しました!

3. 依存パッケージインストール

実行コマンド
# yum install libxml2-devel.x86_64 bzip2-devel.x86_64 libcurl-devel.x86_64 libpng-devel.x86_64 openjpeg-devel.x86_64 freetype-devel.x86_64 t1lib-devel.x86_64 libXpm-devel.x86_64 gd-devel.x86_64 gmp-devel.x86_64 libc-client-devel.x86_64 libicu-devel.x86_64 openldap-devel.x86_64 libmcrypt-devel.x86_64 mysql-devel.x86_64 readline-devel.x86_64 net-snmp-devel.x86_64 libtidy-devel.x86_64 libxslt-devel.x86_64 libmcrypt-devel.x86_64 libevent.x86_64 libevent-devel.x86_64 aspell-devel.x86_64 enchant-devel.x86_64 oniguruma-devel.x86_64 unixODBC-devel.x86_64 sqlite-devel.x86_64 krb5-devel.x86_64
(実行結果)
読み込んだプラグイン:fastestmirror, priorities
Loading mirror speeds from cached hostfile
 * base: mirror.nus.edu.sg
 * extras: mirror.vodien.com
 * updates: mirror.nus.edu.sg
パッケージ libc-client-devel.x86_64 は利用できません。
パッケージ libmcrypt-devel.x86_64 は利用できません。
パッケージ mysql-devel.x86_64 は利用できません。
パッケージ libtidy-devel.x86_64 は利用できません。
パッケージ libmcrypt-devel.x86_64 は利用できません。
パッケージ oniguruma-devel.x86_64 は利用できません。

...

インストール:
  aspell-devel.x86_64 12:0.60.6.1-9.el7              bzip2-devel.x86_64 0:1.0.6-12.el7
  enchant-devel.x86_64 1:1.6.0-8.el7                 freetype-devel.x86_64 0:2.4.11-10.el7_1.1
  gd-devel.x86_64 0:2.0.35-26.el7                    gmp-devel.x86_64 1:6.0.0-11.el7
  krb5-devel.x86_64 0:1.12.2-14.el7                  libXpm-devel.x86_64 0:3.5.10-5.1.el7
  libcurl-devel.x86_64 0:7.29.0-19.el7               libevent.x86_64 0:2.0.21-4.el7
  libevent-devel.x86_64 0:2.0.21-4.el7               libicu-devel.x86_64 0:50.1.2-11.el7
  libpng-devel.x86_64 2:1.5.13-5.el7                 libxml2-devel.x86_64 0:2.9.1-5.el7_1.2
  libxslt-devel.x86_64 0:1.1.28-5.el7                net-snmp-devel.x86_64 1:5.7.2-20.el7_1.1
  openjpeg-devel.x86_64 0:1.5.1-10.el7               openldap-devel.x86_64 0:2.4.39-6.el7
  readline-devel.x86_64 0:6.2-9.el7                  sqlite-devel.x86_64 0:3.7.17-6.el7_1.1
  t1lib-devel.x86_64 0:5.1.2-14.el7                  unixODBC-devel.x86_64 0:2.3.1-10.el7

依存性関連をインストールしました:
  aspell.x86_64 12:0.60.6.1-9.el7                     cyrus-sasl.x86_64 0:2.1.26-17.el7
  cyrus-sasl-devel.x86_64 0:2.1.26-17.el7             elfutils-devel.x86_64 0:0.160-1.el7
  elfutils-libelf-devel.x86_64 0:0.160-1.el7          enchant.x86_64 1:1.6.0-8.el7
  expat-devel.x86_64 0:2.1.0-8.el7                    fontconfig.x86_64 0:2.10.95-7.el7
  fontconfig-devel.x86_64 0:2.10.95-7.el7             fontpackages-filesystem.noarch 0:1.44-8.el7
  gd.x86_64 0:2.0.35-26.el7                           gdbm-devel.x86_64 0:1.10-8.el7
  glib2-devel.x86_64 0:2.40.0-4.el7                   hunspell.x86_64 0:1.3.2-13.el7
  hunspell-en-US.noarch 0:0.20121024-5.el7            jbigkit-libs.x86_64 0:2.0-11.el7
  keyutils-libs-devel.x86_64 0:1.5.8-3.el7            lcms2.x86_64 0:2.5-4.el7
  libICE.x86_64 0:1.0.8-7.el7                         libSM.x86_64 0:1.2.1-7.el7
  libX11.x86_64 0:1.6.0-2.1.el7                       libX11-common.noarch 0:1.6.0-2.1.el7
  libX11-devel.x86_64 0:1.6.0-2.1.el7                 libXau.x86_64 0:1.0.8-2.1.el7
  libXau-devel.x86_64 0:1.0.8-2.1.el7                 libXext.x86_64 0:1.3.2-2.1.el7
  libXpm.x86_64 0:3.5.10-5.1.el7                      libXt.x86_64 0:1.1.4-6.1.el7
  libcom_err-devel.x86_64 0:1.42.9-7.el7              libdb-devel.x86_64 0:5.3.21-17.el7_0.1
  libgcrypt-devel.x86_64 0:1.5.3-12.el7_1.1           libgpg-error-devel.x86_64 0:1.12-3.el7
  libicu.x86_64 0:50.1.2-11.el7                       libjpeg-turbo.x86_64 0:1.2.90-5.el7
  libjpeg-turbo-devel.x86_64 0:1.2.90-5.el7           libpng.x86_64 2:1.5.13-5.el7
  libselinux-devel.x86_64 0:2.2.2-6.el7               libsepol-devel.x86_64 0:2.1.9-3.el7
  libtiff.x86_64 0:4.0.3-14.el7                       libtool-ltdl.x86_64 0:2.4.2-20.el7
  libverto-devel.x86_64 0:0.2.5-4.el7                 libxcb.x86_64 0:1.9-5.el7
  libxcb-devel.x86_64 0:1.9-5.el7                     libxslt.x86_64 0:1.1.28-5.el7
  lm_sensors-devel.x86_64 0:3.3.4-11.el7              lm_sensors-libs.x86_64 0:3.3.4-11.el7
  ncurses-devel.x86_64 0:5.9-13.20130511.el7          net-snmp-agent-libs.x86_64 1:5.7.2-20.el7_1.1
  net-snmp-libs.x86_64 1:5.7.2-20.el7_1.1             openjpeg.x86_64 0:1.5.1-10.el7
  openjpeg-libs.x86_64 0:1.5.1-10.el7                 openssl-devel.x86_64 1:1.0.1e-42.el7.9
  pcre-devel.x86_64 0:8.32-14.el7                     perl-ExtUtils-Install.noarch 0:1.58-285.el7
  perl-ExtUtils-MakeMaker.noarch 0:6.68-3.el7         perl-ExtUtils-Manifest.noarch 0:1.61-244.el7
  perl-ExtUtils-ParseXS.noarch 1:3.18-2.el7           perl-devel.x86_64 4:5.16.3-285.el7
  popt-devel.x86_64 0:1.13-16.el7                     pyparsing.noarch 0:1.5.6-9.el7
  rpm-devel.x86_64 0:4.11.1-25.el7                    systemtap-sdt-devel.x86_64 0:2.6-10.el7_1
  t1lib.x86_64 0:5.1.2-14.el7                         tcp_wrappers-devel.x86_64 0:7.6-77.el7
  unixODBC.x86_64 0:2.3.1-10.el7                      xorg-x11-proto-devel.noarch 0:7.7-8.el7.1
  xz-devel.x86_64 0:5.1.2-9alpha.el7                  zlib-devel.x86_64 0:1.2.7-13.el7

依存性を更新しました:
  freetype.x86_64 0:2.4.11-10.el7_1.1                   libgcrypt.x86_64 0:1.5.3-12.el7_1.1
  libxml2.x86_64 0:2.9.1-5.el7_1.2                      openssl.x86_64 1:1.0.1e-42.el7.9
  openssl-libs.x86_64 1:1.0.1e-42.el7.9                 sqlite.x86_64 0:3.7.17-6.el7_1.1

完了しました!

4. Apache-2.2.31(Webサーバー) をインストール

--> Apatche2.4系でも問題ないかもしれないが、念のためApache2.2系の最新版で試すことに。

実行コマンド
# cd /usr/local/src
# wget http://ftp.yz.yamagata-u.ac.jp/pub/network/apache//httpd/httpd-2.2.31.tar.gz
# tar zxf httpd-2.2.31.tar.gz
# cd httpd-2.2.31 
# ./configure -prefix=/usr/local/apache2 -enable-so -enable-rewrite -enable-ssl -enable-mods-shared=all
# make
# make install

5. bisonの Ver. 2.4.1 を localへインストール

ファイルの文法仕様を読み取って、パーサを生成するツール...らしい。
--> バージョンが新しすぎると警告が出るようなので、localにインストール。

実行コマンド
# cd /usr/local/src
# wget http://ftp.gnu.org/gnu/bison/bison-2.4.1.tar.gz
# tar zxf bison-2.4.1.tar.gz
# cd bison-2.4.1/
# ./configure
# make
# make install 

6. re2cをインストール

字句解析を自動生成する機能を提供するソフトウェア、Flexのようなもの。
PHPのインストールと動作に必要...らしい。

# cd /usr/local/src
# wget http://jaist.dl.sourceforge.net/project/re2c/re2c/0.13.7.5/re2c-0.13.7.5.tar.gz
# tar zxf re2c-0.13.7.5.tar.gz
# cd re2c-0.13.7.5/
# ./configure
# make
# make install 

7. libevent-1.4-15をインストール

非同期IOを実現するライブラリ。PHPのインストールと動作に必要...らしい。
参考記事

# cd /usr/local/src
# wget http://sourceforge.net/projects/levent/files/libevent/libevent-1.4/libevent-1.4.15.tar.gz
# tar zxf libevent-1.4.15.tar.gz
# cd libevent-1.4.15
# ./configure
# make
# make install
# echo "/usr/local/lib" >/etc/ld.so.conf.d/local_lib.conf
# ldconfig 

8. libmcrypt-2.5.7をインストール

暗号化モジュール?。PHPのインストールと動作に必要...らしい。

# cd /usr/local/src
# wget ftp://ftp.linux.co.kr/etc/libmcrypt-2.5.7.tar.gz
# tar zxf libmcrypt-2.5.7.tar.gz
# cd libmcrypt-2.5.7/libltdl
# ./configure --enable-ltdl-install
# make
# make install
# make clean
# ldconfig

phpenv,php-buildのインストール

目次
1. phpenvのインストール
2. php-buildのインストール

1. phpenvのインストール

実行コマンド
$ cd
$ mkdir -p repos/git
$ cd repos/git
$ git clone https://github.com/CHH/phpenv.git
$ cd phpenv/bin
$ ./phpenv-install.sh
$ cd
設定を .bashrc へ追記します。
$ cat ~/.bashrc
.bashrc(ファイル内追記)
    export PATH="~/.phpenv/bin:$PATH"
    eval "$(phpenv init -)"

.bashrcの追記内容をサーバー上に反映させる

実行コマンド
$ source ~/.bashrc
(インストール結果確認)
$ phpenv
rbenv 0.4.0-153-g3b6faa8
Usage: rbenv <command> [<args>]

Some useful rbenv commands are:
   commands    List all available rbenv commands
   local       Set or show the local application-specific Ruby version
   global      Set or show the global Ruby version
   shell       Set or show the shell-specific Ruby version
   rehash      Rehash rbenv shims (run this after installing executables)
   version     Show the current Ruby version and its origin
   versions    List all Ruby versions available to rbenv
   which       Display the full path to an executable
   whence      List all Ruby versions that contain the given executable

See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme 

2. php-buildのインストール

$ git clone https://github.com/CHH/php-build.git ~/.phpenv/plugins/php-build
$ cd ~/.phpenv/plugins/php-build
$ sudo sh install.sh
$ cd
(インストール結果確認)
$ php-build
usage: php-build [options] <definition> <prefix>

  <definition>       What release should be used, as well as release-specific
                     configuration. This is either the name of a builtin
                     definition file (as listed with --definitions) or a path
                     to the definition file.
  <prefix>           All built executables, configurations and libraries are
                     placed in this directory. It's created if it doesn't
                     exist.

  --definitions      Lists all available definitions and exit
  -h|--help          Display this help and exit
  -i|--ini <env>     php.ini to use. If <env> is a file then this file is
                     used, otherwise php.ini-<env> from the source
                     distribution is used. Defaults to "production".
  --pear             Install PEAR alongside of Pyrus (experimental)
  -v|--version       Display version information and exit 

PHPの各バージョンをインストール&エラーを解消

目次(例としてバージョン5.3.3の設定を行う。適宜バージョン番号を変更して実行)
1. 設定ファイルの調整
2. PHP5.3.3 のインストール
3. libxml2のパッチ当て
4. クリアせずに再ビルド

1. 設定ファイルの調整

~/.phpenv/plugins/php-build/share/php-build/definitions/5.3.3 の先頭に設定追加。

実行コマンド
$ $ sed -i '1s,^,configure_option "--with-apxs2" "/usr/local/apache2/bin/apxs"\n,' ~/.phpenv/plugins/php-build/share/php-build/definitions/5.3.3

2. PHP5.3.3 のインストール

実行コマンド
// リトライ時にはtmpディレクトリ配下をお掃除。
// $ sudo rm -rf /tmp/php-build/source/5.3.3
$ phpenv install 5.3.3
(実行結果)
↓下記エラーが出るので・・・
-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
tar (child): bzip2: exec 不能: そのようなファイルやディレクトリはありません
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
-----------------------------------------

The full Log is available at '/tmp/php-build.5.3.3.20150831154631.log'.
[Warn]: Aborting build.

3. libxml2のパッチ当て

実行コマンド
$ cd /tmp
$ curl -O https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt
$ mv /tmp/txtbgxGXAvz4N.txt /tmp/php-patch.txt
$ cd /tmp/php-build/source/5.3.3
$ patch -p0 < /tmp/php-patch.txt <-- このパッチコマンド実行時にエラー?となりました。 
patchコマンド実行結果
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- ext/dom/node.c 2012-08-06 17:49:48.826716692 +0800
|+++ ext/dom/node.c 2012-08-06 17:52:47.633484660 +0800
--------------------------
File to patch: ^C

--> 今ココ!!!!!!!!!!!!!!!

4. クリアせずに再ビルド

...

開発環境でPHPのバージョンを切り替える

...

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