LoginSignup
22
20

More than 5 years have passed since last update.

anyenvでphpenvとrbenvの共存

Posted at

rbenvとphpenvの共存

sassのコンパイルにてcompassが必要になり、Rubyをrbenv経由でインストールしようとした時、もとからphpenvが入っていたため不具合が生じた。
複数の◯◯envを共存させるには、anyenvを使うと良いです。

既存のphpenv/rbenv削除

brewでインストールした場合

$ brew uninstall phpenv 

gitでインストールした場合

$ rm -rf ~/.phpenv

anyenvのinstall

gitでインストールします

$ git clone https://github.com/riywo/anyenv ~/.anyenv

pathの設定

zshを使っています。適宜読み替えて下さい

$ vi ~/.zshrc

.anyenv/envsの中にインストールした◯◯envが入っているので、その数だけPATHを通している

...

if [ -d $HOME/.anyenv ] ; then
    export PATH="$HOME/.anyenv/bin:$PATH"
    eval "$(anyenv init -)"
    # tmux対応
    for D in `\ls $HOME/.anyenv/envs`
    do
        export PATH="$HOME/.anyenv/envs/$D/bin:$PATH"
    done
fi
$ source .zshrc

install rbenv

rbenvをインストールします

$ anyenv install rbenv

install ruby

rubyをインストールします

$ rbenv install 2.3.1
$ rbenv global 2.3.1
$ rbenv rehash
$ ruby --version                                                                                                  
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]

install phpenv

phpenvを改めてインストールします

$ anyenv install phpenv

install php

phpをインストールします

$ phpenv install 7.0.12
$ phpenv global 7.0.12
$ phpenv rehash
$ php --version                                                                                                   
PHP 7.0.12 (cli) (built: Oct 26 2016 22:07:26) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.12, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans

phpインストールでエラーが起きた場合

基本的にコンパルエラーの内容を見て下さい。私の場合は以下の方法で解決しました。
ちなみに、エラー内容は

configure: error: build test failed.  Please check the config.log for details.

と、内容の無いものでした。config.logもどこにあるのかわからなかったです。
以下、解決したログです。

openssl, libxml2, mcryptのPATHを表示します。
まだインストールされていない場合は、brewでインストールしてください

$ echo -e "--with-openssl=$(brew --prefix openssl)\n--with-libxml-dir=$(brew --prefix libxml2)\n--with-mcrypt=$(brew --prefix mcrypt)"
--with-openssl=/usr/local/opt/openssl
--with-libxml-dir=/usr/local/opt/libxml2
--with-mcrypt=/usr/local/opt/mcrypt

以下のとおり、php-buildの設定ファイルを編集します

$ vi .anyenv/envs/phpenv/plugins/php-build/share/php-build/default_configure_options

以下のとおり編集します。
もとからある、--with-opensslを変更。--with-mcryptを変更。--with-libxml-dirを追加

- --with-openssl
+ --with-openssl=/usr/local/opt/openssl
- --with-mcrypt
+ --with-mcrypt=/usr/local/opt/mcrypt

...

+ --with-libxml-dir=/usr/local/opt/libxml2

再度インストールを試して下さい。

参考

https://teratail.com/questions/51089
上記のログで助かりました。ありがとうございます

22
20
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
22
20