先前参考 如何 实现PHP多版本的 共存 和 切换? 实现了Linux(Ubuntu/CentOS)系统下,PHP多版本的切换,但是在 Mac OS 下,由于用户权限控制的比较严格,文章里提到的脚本运行失败(没达到预期效果)。后面采用了其他方式实现了 通过执行脚本自由切换PHP版本:
1、新建 2 个 .bash_profile 文件模板,文件名分别为
/Users/jianbao/.bash_profile_5.6
/Users/jianbao/.bash_profile_7.1
.bash_profile_5.6 文件内容为:
alias ll='ls -alF' alias la='ls -A' alias l='ls -CF' export GOROOT=/usr/local/go export GOPATH=/Users/wenjianbao/GoLandProjects export PHP=/usr/local/php/php-5.6 export PATH=$GOROOT/bin:${GOPATH//://bin:}/bin:$PHP/bin:$PHP/sbin:/usr/local/nginx/sbin:/usr/local/mysql:/usr/local/Cellar/subversion/1.9.4/bin:$PATH JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home CLASSPAHT=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar MAVEN_HOME=/alidata/server/maven TOMCAT_HOME=/alidata/server/tomcat PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$TOMCAT_HOME/bin:$PATH: export JAVA_HOME export CLASSPATH export PATH export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
.bash_profile_7.1 文件内容为:
alias ll='ls -alF' alias la='ls -A' alias l='ls -CF' export GOROOT=/usr/local/go export GOPATH=/Users/wenjianbao/GoLandProjects export PHP=/usr/local/php/php-7.1 export PATH=$GOROOT/bin:${GOPATH//://bin:}/bin:$PHP/bin:$PHP/sbin:/usr/local/nginx/sbin:/usr/local/mysql:/usr/local/Cellar/subversion/1.9.4/bin:$PATH JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home CLASSPAHT=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar MAVEN_HOME=/alidata/server/maven TOMCAT_HOME=/alidata/server/tomcat PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$TOMCAT_HOME/bin:$PATH: export JAVA_HOME export CLASSPATH export PATH export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
2、新建 3 个脚本工具,文件名分别为:
/Users/jianbao/1/stop.sh
/Users/jianbao/1/php-5.6.sh
/Users/jianbao/1/php-7.1.sh
stop.sh 文件内容为:
sudo /usr/local/mysql/mysql stop #sudo /usr/local/nginx/sbin/nginx -s stop sudo killall nginx sudo killall php-fpm
php-5.6.sh 文件内容为:
source /Users/wenjianbao/1/stop.sh cat /Users/wenjianbao/.bash_profile_56 > /Users/wenjianbao/.bash_profile source /Users/wenjianbao/.bash_profile sudo rm -rf /etc/php.ini sudo ln -s /usr/local/php/php-5.6/etc/php.ini /etc/php.ini sudo /usr/local/mysql/mysql start sudo /usr/local/nginx/sbin/nginx sudo /usr/local/php/php-5.6/sbin/php-fpm -D #sudo /usr/local/redis/redis-3.2/redis-server /usr/local/redis/redis-3.2/redis.conf&
php-7.1.sh 文件内容为:
source /Users/wenjianbao/1/stop.sh cat /Users/wenjianbao/.bash_profile_71 > /Users/wenjianbao/.bash_profile source /Users/wenjianbao/.bash_profile sudo rm -rf /etc/php.ini sudo ln -s /usr/local/php/php-7.1/etc/php.ini /etc/php.ini sudo /usr/local/mysql/mysql start sudo /usr/local/nginx/sbin/nginx sudo /usr/local/php/php-7.1/sbin/php-fpm -D #sudo /usr/local/redis/redis-3.2/redis-server /usr/local/redis/redis-3.2/redis.conf &
3、使用方式
切换到 PHP-5.6,执行一下 ./php-5.6.sh;
切换到 PHP-7.1,执行一下 ./php-7.1.sh;
大功告成!