Programming/$_머니 (PHP)

Mac PHP 버전 관리하기 (brew-php-switcher)

귀찮은 개발자 2024. 2. 9. 22:48
더보기

2022 년도에 작성된 글 입니다.

예시

# brew-php-switcher 설치 
brew install brew-php-switcher
brew-php-switcher 8.1
brew-php-switcher 7.4
brew-php-switcher <버전>

# 7.3 버전이 설치되지 않았을 경우 아래와 같이 메세지 출력 
brew-php-switcher 7.3
Sorry, but php@7.3 is not installed via brew. Install by running: brew install php@7.3
# 설치한다. 
brew install php@7.3
# 위에꺼 에러나면 아래껄로 설치한다. 
brew install shivammathur/php/php@7.3
brew install shivammathur/php/php@8.0

결과

~ ➤ brew-php-switcher 8.1
Switching to php@8.1
Switching your shell
Unlinking /usr/local/Cellar/php@7.3/7.3.33_2... 0 symlinks removed.
Unlinking /usr/local/Cellar/php@7.4/7.4.27.reinstall... 0 symlinks removed.
Unlinking /usr/local/Cellar/php/8.1.2... 24 symlinks removed.
Linking /usr/local/Cellar/php/8.1.2... 24 symlinks created.
You will need sudo power from now on
Switching your apache conf
Password:
Restarting apache
All done!


~ ➤ php -v
PHP 8.1.2 (cli) (built: Jan 20 2022 03:49:01) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

이슈

zshrc에 환경변수로 7.4 버전이 작성되어 있다면 brew-php-switcher 가 작동하지 않을 수 있으니 참고