Mac 下更新自带的PHP版本5.3到7.0

2016-3-16 杜世伟 Mac

下载和安装PHP 7.0

打开终端并运行如下的命令:

curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0
回车后,你会看到一个EI Capitan下的警告:

Detected OS X El Capitan 10.11. As this is quite new, there may be issues still. Your mileage may vary.
不用管这个警告,等待下载安装完毕即可。

配置路径

安装完毕如果在终端里运行PHP -v命令,还是会显示mac自带的旧版本。因此,我们还需要配置一下路径。
在命令行中输入如下命令:

sudo vim ~/.bash_profile
然后,在文件的最后加上:

export PATH=/usr/local/php5-7.0.7-20160526-160257/bin:$PATH;
注意:我这里是以安装的PHP7.0的路径来配置的,你需要进到/usr/local中查看你所安装的PHP的路径。
最后,运行命令:

source ~/.bash_profile

配置完成,再试试php -v显示的就是最新安装的PHP版本了。

PHP 7.0.24 (cli) (built: Oct  2 2017 09:17:48) ( NTS )

Copyright (c) 1997-2017 The PHP Group

Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

    with Zend OPcache v7.0.24, Copyright (c) 1999-2017, by Zend Technologies

    with Xdebug v2.5.3, Copyright (c) 2002-2017, by Derick Rethans

如果继续想还原php版本,即把~/.bash_profile文件中注释掉

#export PATH=/usr/local/php5-7.0.7-20160526-160257/bin:$PATH;

然后执行source ~/.bash_profile

此时在执行php -v看下

PHP 5.6.30 (cli) (built: Feb  7 2017 16:18:37) 

Copyright (c) 1997-2016 The PHP Group

Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies


标签: PHP curl install Mac

Powered by emlog 沪ICP备2023034538号-1