美文网首页
Mac下PHP多版本

Mac下PHP多版本

作者: 落单的候鸟 | 来源:发表于2018-01-23 13:48 被阅读0次

    这篇内容是根据以前的安装回忆写出来的,有时间我会具体操作一遍,如果有问题,欢迎指出。

    安装homebrew
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
    安装php56

    安装前需要先执行:

    xcode-select --install
    brew upgrade
    

    Mac下默认安装了php,先不管,我们先安装php5.6(我本地有多个项目,目前还是以php56为主)。

    brew install php56 --with-imap --with-debug --with-mysql  --with-homebrew-curl
    

    安装后,修改路径,替换系统自带php

    echo 'export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH"' >> ~/.bash_profile  #for php
    echo 'export PATH="$(brew --prefix homebrew/php/php56)/sbin:$PATH"' >> ~/.bash_profile  #for php-fpm
    echo 'export PATH="/usr/local/bin:/usr/local/sbin:$PATH"' >> ~/.bash_profile #for other brew install soft
    source ~/.bash_profile  #更新配置
    

    让php-fpm自动启动

    mkdir -p ~/Library/LaunchAgents
    sudo cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
    
    /usr/local/etc/php/5.6/php.ini  #我本地的php.ini路径
    php --ini  #查询php.ini路径
    
    安装 php redis
    brew install php56-redis --build-from-source
    
    安装 php mcrypt
    brew install php56-mcrypt --build-from-source
    
    安装 php igbinary
    brew install php56-igbinary --build-from-source
    

    查看当前php版本

    localhost:~ kangly$ php -v
    PHP 5.6.32 (cli) (built: Dec 22 2017 17:35:30) (DEBUG)
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    
    安装php71
    brew unlink php56 
    brew install php71 --with-fpm --with-homebrew-curl
    

    下面是安装成功后一些重要的提示

    If you need to have this software first in your PATH run:
    echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
    echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.bash_profile
    
    If you need to have this software first in your PATH run:
    echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.bash_profile
    
    If you are having issues with custom extension compiling, ensure that you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:
    PATH="/usr/local/bin:$PATH"
    PHP71 Extensions will always be compiled against this PHP. Please install them using --without-homebrew-php to enable compiling against system PHP.
    
    If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file:
    export PATH="$(brew --prefix homebrew/php/php71)/bin:$PATH"
    
    To launch php-fpm on startup:
    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
    The control script is located at /usr/local/opt/php71/sbin/php71-fpm
    
    OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:
    PATH="/usr/local/sbin:$PATH"
    
    To have launchd start homebrew/php/php71 now and restart at login:
    brew services start homebrew/php/php71
    
    The php.ini file can be found in:
    /usr/local/etc/php/7.1/php.ini
    
    安装php71 redis
    brew install php71-redis
    
    安装 brew-php-switcher
    brew install brew-php-switcher
    
    切换php版本
    brew-php-switcher 56  #切换到php56
    brew-php-switcher 71  #切换到php71
    
    #重启php-fpm
    sudo killall php-fpm
    php-fpm -D
    

    相关文章

      网友评论

          本文标题:Mac下PHP多版本

          本文链接:https://www.haomeiwen.com/subject/fndsaxtx.html