상현
개발 덕후

PHP 버전 쉽게 전환하기

( 업데이트: )

모든 언어가 그렇지만 개발을 하다 보면 프로젝트마다 언어, 의존성 등의 버전을 다르게 해서 개발할 때가 있습니다. PHP 버전을 손쉽게 변경하고 관리할 수 있는 프로그램들을 설치해서 사용해 보도록하겠습니다.

brew-php-switcher 설치

brew install brew-php-switcherCode language: Bash (bash)

PHP 버전 변경 방법

brew-php-switcher 7.2
brew-php-switcher 8.0
brew-php-switcher 8.1Code language: Bash (bash)
brew-php-switcher 7.2
Switching to php@7.2
Switching your shell
Unlinking /opt/homebrew/Cellar/php@7.0/7.0.33_5... 0 symlinks removed.
Unlinking /opt/homebrew/Cellar/php@7.2/7.2.34_4... 0 symlinks removed.
Unlinking /opt/homebrew/Cellar/php@8.0/8.0.22... 25 symlinks removed.
Unlinking /opt/homebrew/Cellar/php/8.1.9... 0 symlinks removed.
Linking /opt/homebrew/Cellar/php@7.2/7.2.34_4... 25 symlinks created.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/opt/homebrew/opt/php@7.2/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/opt/homebrew/opt/php@7.2/sbin:$PATH"' >> ~/.zshrc
You will need sudo power from now on
Switching your apache conf
Password:
Restarting apache
All done!Code language: Bash (bash)
php -v
PHP 7.2.34 (cli) (built: Apr  5 2022 21:34:34) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.34, Copyright (c) 1999-2018, by Zend TechnologiesCode language: Bash (bash)