0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【はじめからていねいに】PHP7.4にアップグレードする方法

Posted at

はじめに

PHPのバージョンが7.2だったので最新のphp7.4にアップグレードしようとしたところつまずいたので備忘録に残しておきます。

手順

まずは自分の環境で使用しているPHPのバージョンを確認してみましょう!
僕の場合はphp7.2.30がインストールされていました。

$ php -v
PHP 7.2.30 (cli) (built: Apr 23 2020 02:40: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

次にhomebrewでphpを検索します。

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

brewでphp7.4をインストールします。

$ brew install php@7.4                                                     

インストールが完了したらPATHを通します。

export PATH="/usr/local/opt/php@7.4/bin:$PATH"
export PATH="/usr/local/opt/php@7.4/sbin:$PATH"                                                     

php7.4をインストールしたしPATHも通したのでこれで完了のはずです!
って意気揚々としていたら、、、あれ??バージョン変わってない。(僕の場合)

$ php -v
PHP 7.2.30 (cli) (built: Apr 23 2020 02:40: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

バージョンが変わっていなかった人向け

手順に沿ってインストールしたつもりが、バージョンが変わっていない人は下記を試してください。

もう1度php7.4をインストールしてみる。

$ brew install php@7.4
Warning: php 7.4.6 is already installed and up-to-date
To reinstall 7.4.6, run `brew reinstall php`

警告が出ていますね。もうすでにインストールしているよって言われてます。
そして、```To reinstall 7.4.6, run `brew reinstall php````とも言われていますね。

警告にしたがってコマンドを実行しましょう。

$ brew reinstall php
==> Reinstalling php 
==> Downloading https://homebrew.bintray.com/bottles/php-7.4.6.catalina.bottle.tar.gz
Already downloaded: /Users/owner/Library/Caches/Homebrew/downloads/01f6c132bb17669a60cff79a15ce162bd084f81177e74902669d7a2033872a8d--php-7.4.6.catalina.bottle.tar.gz
==> Pouring php-7.4.6.catalina.bottle.tar.gz
==> /usr/local/Cellar/php/7.4.6/bin/pear config-set php_ini /usr/local/etc/php/7.4/php.ini system
==> /usr/local/Cellar/php/7.4.6/bin/pear config-set php_dir /usr/local/share/pear system
==> /usr/local/Cellar/php/7.4.6/bin/pear config-set doc_dir /usr/local/share/pear/doc system
==> /usr/local/Cellar/php/7.4.6/bin/pear config-set ext_dir /usr/local/lib/php/pecl/20190902 system
==> /usr/local/Cellar/php/7.4.6/bin/pear config-set bin_dir /usr/local/opt/php/bin system
==> /usr/local/Cellar/php/7.4.6/bin/pear config-set data_dir /usr/local/share/pear/data system
==> /usr/local/Cellar/php/7.4.6/bin/pear config-set cfg_dir /usr/local/share/pear/cfg system
==> /usr/local/Cellar/php/7.4.6/bin/pear config-set www_dir /usr/local/share/pear/htdocs system
==> /usr/local/Cellar/php/7.4.6/bin/pear config-set man_dir /usr/local/share/man system
==> /usr/local/Cellar/php/7.4.6/bin/pear config-set test_dir /usr/local/share/pear/test system
==> /usr/local/Cellar/php/7.4.6/bin/pear config-set php_bin /usr/local/opt/php/bin/php system
==> /usr/local/Cellar/php/7.4.6/bin/pear update-channels
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /usr/local/opt/php/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/

To have launchd start php now and restart at login:
  brew services start php
Or, if you don't want/need a background service you can just run:
  php-fpm
==> Summary
🍺  /usr/local/Cellar/php/7.4.6: 519 files, 76.1MB

再度、phpのバージョンを確認します!

$ php -v
PHP 7.4.6 (cli) (built: May 14 2020 10:38:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies

アップグレードに成功していますね。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?