码迷,mamicode.com
首页 > Web开发 > 详细

mac安装多版本php环境配置

时间:2017-07-08 13:26:06      阅读:328      评论:0      收藏:0      [点我收藏+]

标签:不同的   pid   哪些   php扩展   php7   agent   source   sdn   pre   

1.卸载mac自带的apache和php,有用集成环境,建议也删掉

  先停掉apache:

            sudo apachectl stop

    然后统统删掉

           sudo rm /usr/sbin/httpd
           sudo rm -r /etc/apache2/

 

2.安装Nginx

  安装完后,先不急着修改配置文件

      先设置权限

            sudo chown root:wheel    /usr/local/opt/nginx/bin/nginx
            sudo chmod u+s     /usr/local/opt/nginx/bin/nginx

      如果想设开机启动的话

           mkdir -p  ~/Library/LaunchAgents
           cp   /usr/local/opt/nginx/homebrew.mxcl.nginx.plist    ~/Library/LaunchAgents/
           launchctl  load   -w   ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

            launchctl unload   ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist(取消开机启动)

  nginx命令

           sudo nginx #打开 nginx
           nginx -s reload|reopen|stop|quit  #重新加载配置|重启|停止|退出 nginx
           nginx -t   #测试配置是否有语法错误
           如果提示pid丢失的话,就用这句话
           nginx -c "/usr/local/etc/nginx/nginx.conf"

       好了nginx安装完毕,大家可以localhost一下,就可以看到nginx的信息了

3.安装MYSQL

  brew install mysql

  加入开机启动
              cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
               launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

              launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist(取消开机启动)

       初始化mysql

             cd /usr/local/Cellar/mysql/5.7.18_1/bin

             mysql_install_db

       设置root账户和密码

            ./mysql_secure_installation 一直跟着提示走就行

 

4.先安装php7

  brew install php70  --without-apache --with-fpm

  因为我们用nginx,所有--without-apache,并且加上--with-fpm来编译php

  安装完成加入全局配置环境

  vim   ~/.bash_profile 添加  export PATH=/usr/local/bin:/usr/sbin:$PATH

       然后 vim   ~/.bashrc  添加   export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"

       最后 sourc ~/.bash_profile 

  source ~/.bashrc

  加入开机自启动

  mkdir -p ~/Library/LaunchAgents
       cp /usr/local/opt/php70/homebrew.mxcl.php70.plist     ~/Library/LaunchAgents/
       launchctl   load      -w      ~/Library/LaunchAgents/homebrew.mxcl.php70.plist

5.安装php5.6.30

  brew install php56    --without-apache --with-fpm

  vim   ~/.bashrc  修改[PATH后面的等号不能留空格]

  export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"  为 

  export PATH="$(brew --prefix homebrew/php/php70)/bin:$(brew --prefix  homebrew/php/php56)/bin$PATH";

  加入开机自启                mkdir  -p   ~/Library/LaunchAgents
        cp /usr/local/opt/php70/homebrew.mxcl.php56.plist     ~/Library/LaunchAgents/
        launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist   

 

6.安装php切换工具

  brew install php-version

  执行加入到环境变量   source $(brew --prefix php-version)/php-version.sh 

  echo "source $(brew --prefix php-version)/php-version.sh" >> ~/.bash_profile

  命令行添加  vim  ~/.bashrc 添加  source $(brew --prefix php-version)/php-version.sh && php-version 7.0.20  (后面的是默认开启的php版本; )

  执行  source  ~/.bashrc  后,执行

  source $(brew --prefix php-version)/php-version.sh && php-version 7.0.20

  php-version  可以随意切换

 

7.安装php扩展库

  先查看对应的php版本有哪些扩展  brew  search php70  ;

  然后 brew  install  XXX 安装即可;

 

8.配置Nginx和php-fpm

  nginx 配置 很简单,nginx的配置文件在 /usr/local/etc/nginx/文件中  vim nginx.conf

      然后 根据 自己的需求去配置就行,这里就不用详细说了

      php-fpm的配置:     先cd到  /usr/local/etc/php,你可以看到7.0和5.6这俩个文件夹,至于你想要改哪个,就改就行

 

9.重启Nginx和php-fpm

  sudo killall php-fpm 先停掉所有php-fpm的进程

  cd  /usr/local/Cellar/php/版本号/sbin

  不同版本的php,sbin目录里会有不同的php-fpm,比如php7.0的是php70-fpm, php5.6.18的是 php56-fpm,你想启动哪个fpm就

        sudo ./php70-fpm start 或php56-fpm start就行

 

 

 

 

 

 

 

 

 

  

 

mac安装多版本php环境配置

标签:不同的   pid   哪些   php扩展   php7   agent   source   sdn   pre   

原文地址:http://www.cnblogs.com/paly76/p/7136339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!