程式開發

Mac上切換php版本

使用 brew unlink / link 來切換 php 的版本

以下示範 php 8.1 切換到 7.4

# 查看目前php版本為 8.1
$ php -v
PHP 8.1.6 (cli) (built: May 12 2022 23:44:53) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies

# 查看其他有安裝的版本
$ brew search php
==> Formulae
brew-php-switcher   php@7.2             phplint             pcp
php ✔               php@7.3             phpmd               pup
php-code-sniffer    php@7.4 ✔           phpmyadmin
php-cs-fixer        php@8.0             phpstan
php-cs-fixer@2      phpbrew             phpunit

# 取消目前版本
$ brew unlink php
Unlinking /usr/local/Cellar/php/8.1.6... 24 symlinks removed.

# 更新為 7.4版
$ brew link php@7.4
Linking /usr/local/Cellar/php@7.4/7.4.29... 25 symlinks created.

If you need to have this software first in your PATH instead consider running:
  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目前的版本可以看到已經更新為 7.4囉!
$ php -v
PHP 7.4.29 (cli) (built: Apr 14 2022 11:49:03) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.29, Copyright (c), by Zend Technologies

Leave a Reply

Your email address will not be published.