mac 上安装多个版本的php 并切换

我们用brew来安装php

brew search redis  搜索redis
brew install redis 安装redis


brew list 安装的软件
brew services list 所有的启动
brew services start php 启动php
brew services stop php 关闭php

以下命名%开头的表示输入命令

  1. 查看本地已有的php版本
//查看当前php版本
% php -v
PHP 7.2.26 (cli) (built: Dec 18 2019 15:28:10) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.26, Copyright (c) 1999-2018, by Zend Technologies

//查看安装的php版本,发现php最新版
% brew list | grep php
php

//查找其他版本
% brew search php
==> Formulae
brew-php-switcher       php-cs-fixer            phplint                 phpstan
php ✔                   [email protected]               phpmd                   phpunit ✔
php-code-sniffer        [email protected]                 phpmyadmin

==> Casks
homebrew/cask/eclipse-php                       homebrew/cask/netbeans-php

//安装[email protected]
% brew install [email protected]

//查看并停止当前的php服务
% brew services list
% brew services stop php

//启动[email protected]
% brew services start php@73.
Name    Status  User    Plist
php     stopped         
[email protected] started chentao /Users/chentao/Library/LaunchAgents/[email protected]
redis   started chentao /Users/chentao/Library/LaunchAgents/homebrew.mxcl.redis.plist

//切换系统的php版本
% brew unlink php
% brew link [email protected]

//检查当前系统的php版本
% php -v
PHP 7.2.26 (cli) (built: Dec 18 2019 15:28:10) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.26, Copyright (c) 1999-2018, by Zend Technologies

至此php版本切换至7.2

参考文章

你可能感兴趣的:(mac)