LoginSignup
4
4

More than 1 year has passed since last update.

HomebrewでPHP7.3インストールする方法2022年版

Posted at

まえがき

業務上、PHP8.1とPHP7.3を行き来して作業する必要があったのですが
Homebrewを使ってPHP8.1 → 7.3に切り替えようとしたところ「古いバージョンだからbrew上で管理してないよ!だからインストール出来ないよ!」というエラーが発生。

結構苦労したので、備忘録代わりにメモ。

前提

環境は以下の通りです。

macOS Monterey 12.2.1
Homebrew 3.5.2
PHP 8.1(インストール済み) → 7.3(インストールしたい)

やり方

元々PHPがインストールされていない場合、1行目は不要です。
また、バージョンは各自インストールされているバージョンを指定します。

$ brew unlink php@8.1
$ brew tap shivammathur/php
$ brew reinstall shivammathur/php/php@7.3

パス修正する

$ vi ~/.zshrc
$ source ~/.zshrc

これでOK。

ちなみに

7.3から8.1に戻すときは普通にやればOK。

$ brew unlink php@7.3 && brew link --force --overwrite php@8.1
4
4
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
4
4