Overview
Mac に phpenv + virtphp で pyenv + virtualenv のような環境を作った時のメモ。次回同じ作業をすることになった時のために残しておく。
phpenv
phpenv と名のリポジトリは複数あるが、星の数が多いこちらを使うことにした。
phpenv 自体のインストールは簡単。README どおりにやればすぐ終わる。installer もある。
ただ、php-build (phpenv install で必要) でつまずく。
大体は共有ライブラリが足りないって怒られる。そこは一つ一つ対応。
このあたりはメモをロストしました。。まぁなんとかやれるはず。
最終的にはこちらの記事のとおりに実施すれば解決した。感謝。
$ phpenv versions
* system (set by /Users/tommarute/.phpenv/version)
7.3
7.3.9
virtphp
virtualenv も欲しい。これを入れてみよう。
virtphp.phar
をダウンロードして ~/bin
に置いた後からのメモ。
厳密に言うと bin に置くのはちょっと違うかもしれないが、補完されると嬉しいのでこんな感じにしておく。
$ cd ~/bin
$ chmod 755 virtphp.phar
$ ln -s virtphp.phar virtphp
venv を作ってみる。
(事前に phpenv で元となる version を active にしておくこと)
$ virtphp create myenv
Creating .virtphp directory in user home folder.
Creating the environments.json file.
Creating the env folder to hold the environments.
Checking current environment
Creating directory structure
Creating virtPHP version file
Creating custom php.ini
Wrapping PHP binary
Downloading pear phar file, this could take a while...
Installing PEAR
Saving pear.conf file.
Installing Composer locally
Installing activate/deactive script
Your virtual php environment (myenv) has been created!
You can activate your new environment using: ~$ source /Users/tommarute/.virtphp/envs/myenv/bin/activate
$ virtphp show
+-------+--------------------------------+----------------------------------------------------------+
| Name | Path | ACTIVATE |
+-------+--------------------------------+----------------------------------------------------------+
| myenv | /Users/tommarute/.virtphp/envs | source /Users/tommarute/.virtphp/envs/myenv/bin/activate |
+-------+--------------------------------+----------------------------------------------------------+
activate
$ source /Users/tommarute/.virtphp/envs/myenv/bin/activate
(myenv) $ php -v
PHP 7.3.9 (cli) (built: Feb 2 2020 03:18:47) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
deactivate
(myenv) $ deactivate
$ php -v
PHP 7.1.32 (cli) (built: Oct 2 2019 02:04:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
いい感じになりました。
Bye,