MacにPHP7.4をインストール、ついでにphpのヴァージョンを切り替えられるように。

プログラミング
この記事は約4分で読めます。
記事内に広告が含まれます。

仕事でPHP7.4での開発の依頼が来たのでMacにphp@7.4を導入した。
いまだに7.1や7.2の案件も残っているのでswitch-phpで環境を切り替えられるようにします。

switch-phpを実行してみると、7.3までしか対応していませんでした。
サイトを調べたら7.4に対応したVersionが出ていたので導入。

スポンサーリンク

手順

brewで導入した場所にあったswitch-phpを削除し
Gitから取得しました。
[bash]
% cd ~/.nodebrew/current/lib/node_modules
% rm -rf switch-php
% git clone https://github.com/jalendport/switch-php.git
[/bash]
中身を入れ替えたらphp7.4にスイッチ出来ました。

[bash]
Usage:
version [options] [arguments]

Options:
-h, –help Display this help message
-v, –verbose Display more info during the process
-m, –memory Customize the PHP memory setting (Valet only)

Available Versions:
5.6 Switch to php5.6
7.0 Switch to php7.0
7.1 Switch to php7.1
7.2 Switch to php7.2
7.3 Switch to php7.3
7.4 Switch to php7.4

Customizing the PHP Memory Settings:
– If you don’t pass an argument to "-m" or "–memory", it will reset any previously set custom memory settings to the default Valet config.
– Alternatively, you can pass an argument to "-m" or "–memory" if you want to override the default Valet memory settings. For example, you can do:

switch-php 7.1 -m 512M # php@7.1 with 512MB of memory
switch-php 7.3 -m 2G -v # php@7.3 with 2GB of memory; verbose output
switch-php 5.6 –memory=1G # php@5.6 with 1GB of memory

– Note: customizing PHP memory settings currently only works for Laravel Valet users. If you don’t use Valet, we hope to get this working for you as well in an upcoming release.
[/bash]

確認
[bash]
% switch-php 7.4
Password:
Valet stopped ✔
PHP switched ✔
Valet started ✔

You are now using PHP 7.4.7
% php -v
PHP 7.4.7 (cli) (built: Jun 12 2020 00:04:10) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.7, Copyright (c), by Zend Technologies
%
[/bash]

無事7.4の環境ができました。

コメント

タイトルとURLをコピーしました