Macで複数バージョンのPHPをインストールし切り替える

プログラミング
この記事は約3分で読めます。
記事内に広告が含まれます。
スポンサーリンク

利用可能なPHPのバージョンを調べる

$ brew search php
php@7.1 php@7.2 php@7.3

この場合php7.1〜7.3が利用可能です。

複数のバージョンのPHPをインストール

$ brew install php@7.1
$ brew install php@7.2
$ brew install php@7.3

バージョン切り替えツールの導入

$ npm install --global switch-php

動作確認

$ npm switch-php
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

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.

Versionの切り替え

$ switch-php 7.3 512M  # php7.3でメモリ512Mに切り替え

コメント

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