Mac php の複数バージョンを管理する方法

結論:phpbrewを利用する。


これが参考になりそう

pointsandlines.jp

$ curl -L -O https://github.com/phpbrew/phpbrew/releases/latest/download/phpbrew.phar
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   138  100   138    0     0    267      0 --:--:-- --:--:-- --:--:--   267
100   634  100   634    0     0    646      0 --:--:-- --:--:-- --:--:--  619k
100  627k  100  627k    0     0   239k      0  0:00:02  0:00:02 --:--:--  731k
$ ls
Applications			PhpstormProjects		budget_execution
Applications (Parallels)	Pictures			cloud_sql_proxy
Desktop				Postman				java_error_in_pycharm_14726.log
Documents			Public				method.py
Downloads			PycharmProjects			myfunc.py
Dropbox				VirtualBox VMs			phpbrew.phar
Google ドライブ			WebstormProjects		td_budget
Library				account-classifier		toridoll-bugdet
Movies				algorithm.py			vagrant
Music				anaconda3
Parallels			budget-execution
$ chmod +x phpbrew.phar 
$ sudo mv phpbrew.phar /usr/local/bin/phpbrew
Password:  
$ phpbrew init
Using root: /Users/xxxxxxx/.phpbrew
Initialization successfully finished!
<=====================================================>
Phpbrew environment is initialized, required directories are created under

    /Users/xxxxxxx/.phpbrew

Paste the following line(s) to the end of your ~/.bashrc and start a
new shell, phpbrew should be up and fully functional from there:

    source /Users/xxxxxxx/.phpbrew/bashrc

To enable PHP version info in your shell prompt, please set PHPBREW_SET_PROMPT=1
in your `~/.bashrc` before you source `~/.phpbrew/bashrc`

    export PHPBREW_SET_PROMPT=1

To enable .phpbrewrc file searching, please export the following variable:

    export PHPBREW_RC_ENABLE=1


For further instructions, simply run `phpbrew` to see the help message.

Enjoy phpbrew at $HOME!!

<=====================================================>
$ echo 'source ~/.phpbrew/bashrc' >> ~/.bashrc
$ phpbrew lookup-prefix homebrew
Did you mean 'self-update'? [Y/n] Y
Updating phpbrew /usr/local/bin/phpbrew...
downloading via curl command
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   138  100   138    0     0    416      0 --:--:-- --:--:-- --:--:--   416
100   634  100   634    0     0   1816      0 --:--:-- --:--:-- --:--:--  1816
100  627k  100  627k    0     0   215k      0  0:00:02  0:00:02 --:--:--  308k
Version updated.
Using root: /Users/xxxxxxx/.phpbrew
Initialization successfully finished!
<=====================================================>
Phpbrew environment is initialized, required directories are created under

    /Users/xxxxxxx/.phpbrew

Paste the following line(s) to the end of your ~/.bashrc and start a
new shell, phpbrew should be up and fully functional from there:

    source /Users/xxxxxxx/.phpbrew/bashrc

To enable PHP version info in your shell prompt, please set PHPBREW_SET_PROMPT=1
in your `~/.bashrc` before you source `~/.phpbrew/bashrc`

    export PHPBREW_SET_PROMPT=1

To enable .phpbrewrc file searching, please export the following variable:

    export PHPBREW_RC_ENABLE=1


For further instructions, simply run `phpbrew` to see the help message.

Enjoy phpbrew at $HOME!!

<=====================================================>
phpbrew - 1.26.0
cliframework core: 2.5.4
$ 






Catalinaを利用している場合は、5系が入らない。そこでシステム側へ無理やり
入れてあげる事にする。

$ curl -s https://php-osx.liip.ch/install.sh | bash -s 5.5
Detected macOS Catalina 10.15. All ok.
Get packager.tgz
Unpack packager.tgz
Please type in your password, as we want to install this into /usr/local
Password:
Start packager (may take some time) using /usr/bin/python2.7
downloading https://s3-eu-west-1.amazonaws.com/php-osx.liip.ch/install/5.5-10.10-frontenddev-latest.dat
downloading https://s3-eu-west-1.amazonaws.com/php-osx.liip.ch/install/5.5-10.10/frontenddev/5.5-10.10-frontenddev-5.5.38-20160831-100002.tar.bz2

Installing package 5.5-10.10-frontenddev into root /
./pkg/pre-install
pkg/pre-install
Skipping existing directory 
Skipping existing directory usr/
Skipping existing directory usr/local/
Extracting usr/local/php5-5.5.38-20160831-100002/
Extracting usr/local/php5-5.5.38-20160831-100002/bin/
Extracting usr/local/php5-5.5.38-20160831-100002/entropy-php.conf
Extracting usr/local/php5-5.5.38-20160831-100002/etc/
Extracting usr/local/php5-5.5.38-20160831-100002/include/
Extracting usr/local/php5-5.5.38-20160831-100002/info/
Extracting usr/local/php5-5.5.38-20160831-100002/lib/
Extracting usr/local/php5-5.5.38-20160831-100002/libphp5.so
Extracting usr/local/php5-5.5.38-20160831-100002/php.d/
・
・
・
Extracting usr/local/php5-5.5.38-20160831-100002/bin/tsql
Extracting usr/local/php5-5.5.38-20160831-100002/bin/uconv
Extracting usr/local/php5-5.5.38-20160831-100002/bin/vacuumdb
Extracting usr/local/php5-5.5.38-20160831-100002/bin/wrjpgcom
Extracting usr/local/php5-5.5.38-20160831-100002/bin/xgettext
Extracting usr/local/php5-5.5.38-20160831-100002/bin/xslt-config
Extracting usr/local/php5-5.5.38-20160831-100002/bin/xsltproc
Executing post-install script /tmp/5.5-10.10-frontenddev-post-install
Create symlink /usr/local/php5/entropy-php.conf /etc/apache2/other/+php-osx.conf
Restarting Apache
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using MacBook-Pro.local. Set the 'ServerName' directive globally to suppress this message
Syntax OK
Finished.
$ export PATH=/usr/local/php5/bin:$PATH
$ php -v
PHP 5.5.38 (cli) (built: Aug 31 2016 09:57:16) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
$ which php
/usr/local/php5/bin/php


パスを通す時は、

$ export PATH=/usr/local/php5/bin:$PATH

をしてあげる

おしまい