liip 脚本升级 Mac 自带 PHP

https://php-osx.liip.ch/install.sh | bash -s 7.1

1、安装脚本

1.1、终端执行命令,7.1 为 PHP 安装的版本。

curl -s https://php-osx.liip.ch/install.sh | bash -s 7.1

1.2、脚本完整代码

#!/bin/bash

# package type (subfolder in packager)

# default version to install
DEFAULT=5.6

if [ -z $1 ]; then
TYPE=$DEFAULT
else
TYPE=$1
fi

if [[ $TYPE != "force" ]]; then
OS_VERSION=`sw_vers -productVersion | egrep --color=never -o '10\.[0-9]+'`
if [[ $OS_VERSION == "10.13" ]]; then
echo "****"
echo "[WARNING]"
echo "Detected macOS High Sierra 10.13. As this is quite new, there may be issues still. Your mileage may vary."
echo "****"
sleep 2
elif [[ $OS_VERSION == "10.12" ]]; then
echo "Detected macOS Sierra 10.12. All ok."
elif [[ $OS_VERSION == "10.11" ]]; then
echo "Detected OS X El Capitan 10.11. All ok."
elif [[ $OS_VERSION == "10.10" ]]; then
echo "Detected OS X Yosemite 10.10. All ok."
elif [[ $OS_VERSION == "10.9" ]]; then
echo "Detected OS X Mavericks 10.9 All ok."
elif [[ $OS_VERSION == "10.8" ]]; then
echo "Detected OS X Mountain Lion 10.8 All ok."
elif [[ $OS_VERSION == "10.7" ]]; then
echo "Detected OS X Lion 10.7. All ok."
elif [[ $OS_VERSION == "10.6" ]]; then
echo "Detected OS X Snow Leopard 10.6 All ok."
else
echo "****"
echo "Your version of OS X ($OS_VERSION) is not supported, you need at least 10.6"
echo "Stopping installation..."
echo "If you think that's wrong, try"
echo "****"
echo "curl -o install.sh -s https://php-osx.liip.ch/install.sh | bash install.sh force"
echo "****"
exit 2
fi
if [[ -f /usr/sbin/sysctl ]]; then
SYSCTL="/usr/sbin/sysctl"
elif [[ -f /sbin/sysctl ]]; then
SYSCTL="/sbin/sysctl"
else
SYSCTL="sysctl"
fi

HAS64BIT=`$SYSCTL -n hw.cpu64bit_capable 2> /dev/null`
if [[ $HAS64BIT != 1 ]]; then
echo "****"
echo "ERROR! 32 BIT NOT SUPPORTED!"
echo "****"
echo "No 64bit capable system found. Your hardware is too old."
echo "We don't support that (yet). Patches are welcome ;)"
echo "If you think that's wrong, try"
echo "****"
echo "curl -o install.sh -s https://php-osx.liip.ch/install.sh | bash install.sh force"
echo "****"
exit 1
fi
fi

if [[ $TYPE = "force" ]]; then
if [ -z $2 ]; then
TYPE=$DEFAULT
else
TYPE=$2
fi
fi

if [[ $OS_VERSION = "10.8" ]] || [[ $OS_VERSION = "10.9" ]]; then
if [[ $TYPE = "5.4" ]]; then
TYPE=5.4-10.8
elif [[ $TYPE = "5.5" ]]; then
TYPE=5.5-10.8
elif [[ $TYPE = "5.6" ]]; then
TYPE=5.6-10.8
elif [[ $TYPE = "5.3" ]]; then
TYPE=5.3-10.8
fi
fi

# 10.11 & 10.12 should be compatible with 10.10 versions for now.
# See https://github.com/liip/build-entropy-php/issues/16 for more
if [[ $OS_VERSION = "10.11" ]] || [[ $OS_VERSION = "10.12" ]] || [[ $OS_VERSION = "10.13" ]] || [[ $OS_VERSION = "10.10" ]]; then
if [[ $TYPE = "5.4" ]]; then
TYPE=5.4-10.10
elif [[ $TYPE = "5.5" ]]; then
TYPE=5.5-10.10
elif [[ $TYPE = "5.6" ]]; then
TYPE=5.6-10.10
elif [[ $TYPE = "7.0" ]]; then
TYPE=7.0-10.10
elif [[ $TYPE = "7.1" ]]; then
TYPE=7.1-10.10
elif [[ $TYPE = "7.2" ]]; then
TYPE=7.2-10.10
elif [[ $TYPE = "5.3" ]]; then
TYPE=5.3-10.10
fi
fi

if [[ $TYPE = "5.6" ]]; then
echo "PHP 5.6 is not available for OS X < 10.8"
exit 1
elif [[ $TYPE = "7.2" ]]; then
echo "PHP 7.2 is not available for OS X < 10.10"
exit 1
elif [[ $TYPE = "7.1" ]]; then
echo "PHP 7.1 is not available for OS X < 10.10"
exit 1
elif [[ $TYPE = "7.0" ]]; then
echo "PHP 7.0 is not available for OS X < 10.10"
exit 1
fi



echo "Get packager.tgz";
curl -s -o /tmp/packager.tgz https://s3-eu-west-1.amazonaws.com/php-osx.liip.ch/packager/packager.tgz

echo "Unpack packager.tgz";
echo "Please type in your password, as we want to install this into /usr/local"
if [ ! -d /usr/local ] ; then sudo mkdir /usr/local; fi
sudo tar -C /usr/local -xzf /tmp/packager.tgz

if [[ -f /usr/bin/python2.7 ]]; then
PYTHONPATH=/usr/bin/python2.7
elif [[ -f /usr/bin/python2.6 ]]; then
PYTHONPATH=/usr/bin/python2.6
elif [[ -f /usr/bin/python ]]; then
PYTHONPATH=/usr/bin/python
else
PYTHONPATH=$(which python)
fi

echo "Start packager (may take some time) using $PYTHONPATH";

sudo $PYTHONPATH /usr/local/packager/packager.py install $TYPE-frontenddev
cd $ORIPWD
echo "Finished."

2、脚本执行顺序

  • 监测环境
  • 下载 packager.tgz
  • 解压 packager.tgz ,运行其中 pythony 脚本

  到此之前一切顺利,到了python脚本的时候,要下载一个更新包,就卡住了,第一行是获取最新的更新包url,第二行是下载并保存这个更新包,浏览器打开这个 URL ,发现速度很慢,尝试复制地址到迅雷,速度很快。

downloading https://s3-eu-west-1.amazonaws.com/php-osx.liip.ch/install/7.1-10.10-frontenddev-latest.dat
downloading https://s3-eu-west-1.amazonaws.com/php-osx.liip.ch/install/7.1-10.10/frontenddev/7.1-10.10-frontenddev-7.1.29-20170114-210819.tar.bz2

3、修改 pythony 代码

修改代码直接执行本地下载好的包

# 修改前
def __fetchIndividual(self, url):
try:
print "downloading %s" % url
filename, headers = urllib.urlretrieve(url)
print "filename: %s" % filename
self.__filename = filename
self.__file = tarfile.open(self.__filename, 'r')
self.__file.errorlevel = 2
return True
except IOError:
return False
except tarfile.ReadError:
return False
# 修改后
def __fetchIndividual(self, url):
try:
print "downloading %s" % url
# 修改开始,修改为本地地址
if url.find('7.1-10.10-frontenddev-7.1.29-20170114-210819.tar.bz2'):
filename = "/usr/local/packager/tmp/7.1-10.10-frontenddev-7.1.29-20170114-210819.tar.bz2"
else:
filename, headers = urllib.urlretrieve(url)
print "filename: %s" % filename
# 修改结束
self.__filename = filename
self.__file = tarfile.open(self.__filename, 'r')
self.__file.errorlevel = 2
return True
except IOError:
return False
except tarfile.ReadError:
return False

4、执行 pythony 代码

sudo /usr/local/packager/packager.py install 7.1-10.10-frontenddev

5、调整系统变量路径

5.1、把php7加入环境变量

  • 打开变量文件 sudo vim ~/.bash_profile
  • 加入 export PATH=/usr/local/php5/bin:$PATH

5.2、安装完成之后,php -m,发现连xdebug 、 Zend OPcache 也一起安装好了。

$ php -v
PHP 7.1.4 (cli) (built: May 6 2017 10:02:00) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.4, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.5.3, Copyright (c) 2002-2017, by Derick Rethans


下一篇 RESTful API
上一篇 PSR PHP 标准规范
查看评论