Skip to content

Instantly share code, notes, and snippets.

@zhouyl
Last active May 28, 2018 08:23
Show Gist options
  • Select an option

  • Save zhouyl/bd4bcbc6ab4c2a7ce89d47ebef255908 to your computer and use it in GitHub Desktop.

Select an option

Save zhouyl/bd4bcbc6ab4c2a7ce89d47ebef255908 to your computer and use it in GitHub Desktop.
PHP 版本切换脚本

PHP 版本切换脚本

需要将 PHP 各版本安装到 /usr/local/php$VER/ 目录下

保存 php-switch 到 /usr/local/bin目录下

执行以下命令

   chmod +x /usr/local/bin/php-switch
   vim /etc/profile.d/apps-bin-path.sh

apps-bin-path.sh 添加如下内容

 export PHP_PATH=/usr/local/php
 PATH=$PHP_PATH/bin:$PATH

    尝试运行一次

  zhouyl:~ $ php-switch 
  PHP 7.0.17 (cli) (built: Mar 21 2017 11:25:34) ( NTS )
  Copyright (c) 1997-2017 The PHP Group
  Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
      with Zend OPcache v7.0.17, Copyright (c) 1999-2017, by Zend Technologies
      with Xdebug v2.5.1, Copyright (c) 2002-2017, by Derick Rethans
  zhouyl:~ $ php-switch 5.5
  PHP 5.5.38 (cli) (built: Mar 21 2017 11:42:15) 
  Copyright (c) 1997-2015 The PHP Group
  Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
      with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
      with Xdebug v2.5.1, Copyright (c) 2002-2017, by Derick Rethans
#!/usr/bin/env bash
VER=$1
if [ ! -z $VER ] ; then
PATH=/usr/local/php$VER
if [ ! -d $PATH ] ; then
echo 'Invalid PHP version: $VER'
exit 0
else
/usr/bin/sudo /bin/rm -f /usr/local/php
/usr/bin/sudo /bin/ln -s $PATH /usr/local/php
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment