3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

anyenv + phpenv で php7.2.3をビルドする

Last updated at Posted at 2018-03-27

環境

  • CentOS7 1708(Minimal)

準備

CentOS更新

$ yum update

依存関係インストール

$ yum install gcc gcc-c++ wget unzip automake curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker

Gitを入れる

# https://mirrors.edge.kernel.org/pub/software/scm/git/ 参考に最新のソースをwget
# 18/03/28 時点では 2.16.3
$ wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.16.3.tar.gz
$ tar zxvf git-2.16.3.tar.gz
$ cd git-2.16.3
$ make prefix=/usr/local all
$ make prefix=/usr/local install

これで以下のようにメッセージが出れば成功

$ git --version
# git version 2.16.3

anyenvを入れる

$ git clone https://github.com/riywo/anyenv ~/.anyenv
$ echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.bash_profile &&
$ echo 'eval "$(anyenv init -)"' >> ~/.bash_profile &&
$ exec $SHELL -l # Shell再読込

これで anyenvコマンドが使用できるはず。

$ anyenv
# anyenv 
# Usage: anyenv <command> [<args>]
# 
# Some useful anyenv commands are:
#    commands            List all available anyenv commands
#    local               Show the local application-specific Any version
#    global              Show the global Any version
#    install             Install a **env
#    uninstall           Uninstall a specific **anv
#    version             Show the current Any version and its origin
#    versions            List all Any versions available to **env
#
# See `anyenv help <command>' for information on a specific command.
# For full documentation, see: https://github.com/riywo/anyenv#readme

phpenvを入れる

$ anyenv install phpenv
$ exec $SHELL -l # Shell再読込

これでphpenvコマンドが使用できる。

$ phpenv
# phpenv:
# =======
#   PHP multi-version installation and management utility.
#
# Usage: phpenv <command> [<args>]
#
# Some useful phpenv commands are:
#   commands    List all available phpenv commands
#   configure   Edit the current PHP's php.ini configuration file at location
#   local       Set or show the local application-specific PHP version
#   global      Set or show the global PHP version and update the Apache apxs
#   shell       Set or show the shell-specific PHP version
#   install     Install a PHP version using the php-build plugin
#   uninstall   Uninstall a specific PHP version using the php-build plugin
#   rehash      Rehash phpenv shims (run this after installing executables)
#   version     Show the current PHP version and its origin
#   versions    List all PHP versions available to phpenv
#   which       Display the full path to an executable
#   whence      List all PHP versions that contain the given executable
#
# See `phpenv help <command>' for information on a specific command.
# For full documentation, see: https://github.com/madumlao/phpenv#readme

phpのビルド環境を整える

phpに必要な依存関係をインストール

yum install libxml2-devel bison bison-devel curl-devel libjpeg-devel libpng-devel readline-devel libxslt-devel httpd-devel enchant-devel libXpm libXpm-devel freetype-devel t1lib t1lib-devel gmp-devel libicu-devel net-snmp net-snmp-devel bzip2 bzip2-devel

php7.2から削除されたmcryptを付けるオプションをデフォルトのビルド設定から削除

sed -i -e '/--with-mcrypt/d' /root/.anyenv/envs/phpenv/plugins/php-build/share/php-build/default_configure_options

libtidyをyum標準で入れられないので使わないし面倒だから削除

sed -i -e '/--with-tidy/d' /root/.anyenv/envs/phpenv/plugins/php-build/share/php-build/default_configure_options

使う人は以下のコマンドでlibtidy-develを入れる。

$ yum install epel-release
$ yum --enablerepo=epel install libtidy-devel

このままビルドするとre2c0.13.4以上にしろと言って怒られる。
が、yum標準リポジトリにはre2cは存在しないので、自分でビルドする。

$ git clone https://github.com/skvadrik/re2c
$ cd re2c
$ ./configure
$ make
$ make install

phpをビルド

# インストールできる最新のものを探す
$ phpenv install -l
# (略)
#  7.1.0
#  7.1.1
#  7.1.2
#  7.1.3
#  7.1.4
#  7.1.5
#  7.1.6
#  7.1.7
#  7.1.8
#  7.1.9
#  7.1.10
#  7.1.11
#  7.1.12
#  7.1.13
#  7.1.14
#  7.1.15
#  7.1snapshot
#  7.2.0
#  7.2.1
#  7.2.2
#  7.2.3
#  7.2snapshot
#  master

今回は7.2.3をビルドする。

$ phpenv install 7.2.3
[Info]: Loaded extension plugin
[Info]: Loaded apc Plugin.
[Info]: Loaded composer Plugin.
[Info]: Loaded github Plugin.
[Info]: Loaded uprofiler Plugin.
[Info]: Loaded xdebug Plugin.
[Info]: Loaded xhprof Plugin.
[Info]: Loaded zendopcache Plugin.
[Info]: php.ini-production gets used as php.ini
[Info]: Building 7.2.3 into /root/.anyenv/envs/phpenv/versions/7.2.3
Preparing]: /tmp/php-build/source/7.2.3
Compiling]: /tmp/php-build/source/7.2.3

[Compiling]から結構長い。
終わったら以下のコマンドでphpに割り当てるバージョンを7.2.3にする。

$ phpenv global 7.2.3
$ php -v
# PHP 7.2.3 (cli) (built: Mar 27 2018 23:08:09) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
#     with Zend OPcache v7.2.3, Copyright (c) 1999-2018, by Zend Technologies
#     with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

ok.

3
6
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
3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?