LoginSignup
0
0

More than 3 years have passed since last update.

homebrewを使ってPHPのバージョンアップグレード

Posted at

概要

homebrewを使ってPHPのバージョンアップグレードを行います。
php7.2系 → php7.3系

homebrewのインストール

Homebrewのインストールがまだの方は、以下の記事を参考に導入をおこなってください。

MacでLaravel開発環境構築 -Qiita

手順

現在のバージョンを確認します。

$ php -v
PHP 7.2.30 (cli) (built: Apr 23 2020 01:23:39) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.30, Copyright (c) 1999-2018, by Zend Technologies

現在バージョンはPHP 7.2.30であることが確認できました。

続いてbrew searchコマンドでインストール可能なPHPのバージョンを確認します。

$ brew search php@7
==> Formulae
php@7.2 ✔   php@7.3   php@7.4

現在インストールされているバージョンの横にチェックマークがついています。

brew installコマンドでphp@7.3をインストールしましょう。

brew install php@7.3

これでphp@7.3をインストールすることができました。

続いてPATHを通す作業をします。
さきほどのインストール実行文の中に、PATHをまだ通してなかったら以下のコマンドを実行してくださいと書いてあります。

If you need to have php@7.3 first in your PATH run:
  echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.bash_profile

これをこのままコピー&ペーストして実行します。

$ echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.bash_profile
$ echo 'export PATH="/usr/local/opt/openldap/sbin:$PATH"' >> ~/.bash_profile

こちらも実行文の中に書かれているのですが、
PHP を自動起動するよう設定をしてから再起動すればphp@7.3になるとのことです。

To have launchd start php@7.3 now and restart at login:
  brew services start php@7.3
Or, if you don't want/need a background service you can just run:
  php-fpm

以下のコマンドを実行します。

$ brew services start php

実行後、ターミナルアプリを開き直して $ php -v でバージョンを確認

$ php -v
PHP 7.3.17 (cli) (built: Apr 29 2020 17:27:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.17, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.17, Copyright (c) 1999-2018, by Zend Technologies

無事 php@7.2系 から php@7.3系 にバージョンアップすることができました。

以上でhomebrewを使ってPHPのバージョンアップグレードは終了です。
お疲れ様でした。

0
0
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
0
0