LoginSignup
2
1

More than 1 year has passed since last update.

Mac CatalinaにてPHPバージョンを7.3から7.4にアップグレード

Posted at

はじめに

MacOS内のPHPバージョンを7.3から7.4にあげる必要があったのですが、すんなりいかなかったので備忘録として残しておきます。

手順

1. 現在のPHPバージョン確認

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

$ php -v
PHP 7.3.11 (cli) (built: Jun  5 2020 23:50:40) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies

7.3ですね。

2. HomebrewにてPHP7.4のインストール

Homebrewにて7.4をインストールします。

まずはHomebrewをアップデート

$ brew update

7.4のインストール

$ brew install php@7.4
Error: Permission denied @ apply2files - /usr/local/share/locale/cs/LC_MESSAGES/libidn2.mo
Warning: Already linked: /usr/local/Cellar/libidn2/2.3.1
To relink, run:
  brew unlink libidn2 && brew link libidn2

残念。エラーです。

リンクが影響しているということなので言われた通りリンクを貼り直してみます

$ brew unlink libidn2
Unlinking /usr/local/Cellar/libidn2/2.3.1... Error: Permission denied @ apply2files - /usr/local/share/locale/cs/LC_MESSAGES/libidn2.mo

Permissionで怒られました。
権限変更してみます。

$ sudo chown -R $(whoami) /usr/local
chown: /usr/local: Operation not permitted

失敗!
High Sierraから/usr/localの権限変更ができなくなったようです。

階層絞って再度やってみます。

$ sudo chown -R $(whoami) /usr/local

うまくいったぽいので再チャレンジ

$ brew unlink libidn2 && brew link libidn2 

Unlinking /usr/local/Cellar/libidn2/2.3.1... 43 symlinks removed.
Linking /usr/local/Cellar/libidn2/2.3.1... 51 symlinks created.

できた

これでようやくインストールできそうです。

$ brew install php@7.4 
(中略)
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /usr/local/opt/php@7.4/lib/httpd/modules/libphp7.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/7.4/

php@7.4 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

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

For compilers to find php@7.4 you may need to set:
  export LDFLAGS="-L/usr/local/opt/php@7.4/lib"
  export CPPFLAGS="-I/usr/local/opt/php@7.4/include"


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

ようやくできました。

3. PHP7.4の適用

パスを通して

$ echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
$ echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc

PHPをリスタートして

$ brew services start php@7.4

変更を反映すれば

$ source ~/.zshrc
$ php -v
PHP 7.4.21 (cli) (built: Jul 12 2021 11:52:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies

バージョンが7.4へと更新されました!

おわりに

一瞬でいけるかと考えてましたが思いの外時間かかりました。
誰かの助けになれば幸いです!

参考

2
1
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
2
1