mac 安装 php nginx mysql

mac下面安装php nginx mysql根linux下面差不多,建议大家使用brew管理工具包安装。

1,安装homebrew

http://brew.sh/index_zh-cn.html

安装方法会改变的,所以安装官方上面的方法来装。安装 homebrew-cask

  1. $ brew tap caskroom/cask  

homebrew-cask安装的东西,更多。

2,换源或者加代理

brew管理工具包,默认是从github上面下载,github经常被墙。并且龟速。

  1. $ brew install git  
  2. $ cd /usr/local/Homebrew  
  3. $ git remote set-url origin https://git.coding.net/homebrew/homebrew.git  

如果不想换源话,可以加代理,前提是你的代理,不被墙,并且比较快

  1. zhangyingdeMacBook-Pro:Homebrew zhangying$ cat ~/.curlrc  
  2. socks5="127.0.0.1:1080"  

3,安装nginx mysql

  1. $ brew install nginx mysql  

4,安装php

  1. //添加扩展库  
  2. $ brew tap homebrew/dupes  
  3. $ brew tap homebrew/versions  
  4. $ brew tap homebrew/php  
  5.   
  6. $ brew search php //查看php的可用版本  
  7. $ brew install php54 //安装所需版本  
  8.   
  9. //默认是有php的,所以php的环境要指向新的  
  10. echo 'export PATH="$(brew --prefix homebrew/php/php54)/bin:$PATH"' >> ~/.bash_profile  
  11. echo 'export PATH="$(brew --prefix homebrew/php/php54)/sbin:$PATH"' >> ~/.bash_profile  
  12. echo 'export PATH="/usr/local/bin:/usr/local/sbin:$PATH"' >> ~/.bash_profile  
  13. $ source ~/.bash_profile //更新配置  

5,配置文件目录

  1. /usr/local/etc/nginx  
  2. /usr/local/etc/php  
  3. /usr/local/Cellar/mysql/5.7.16  

6,开机启动,以nginx为例

  1. $ ln -s /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents/  
  2. $ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist   //加载  
  3. $ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist     //取消加载  

7,sudo无密码

  1. $ sudo su  
  2. # visudo  
  3. %admin   ALL = NOPASSWD:ALL  //admin组的成员,sudo不用输入密码了  

8,如果不想自启动,可以用启动脚本

    1. #!/bin/bash  
    2.   
    3. param=$1  
    4.   
    5. start()  
    6. {  
    7.   
    8.  #启动nginx  
    9.  sudo nginx    //nginx需要root用户来启动  
    10.  #启动mysql  
    11.  mysql.server start  
    12.  #启动php-fpm  
    13.  fpms=`ps aux | grep -i "php-fpm" | grep -v grep | awk '{print $2}'`  
    14.  if [ ! -n "$fpms" ]; then  
    15.  php-fpm  
    16.  echo "PHP-FPM Start"  
    17.  else  
    18.  echo "PHP-FPM Already Start"  
    19.  fi  
    20. }  
    21.   
    22. stop()  
    23. {  
    24.   
    25.  #停止nginx  
    26.  sudo nginx -s stop  
    27.  #停止mysql  
    28.  mysql.server stop  
    29.  #停止php-fpm  
    30.  fpms=`ps aux | grep -i "php-fpm" | grep -v grep | awk '{print $2}'`  
    31.  echo $fpms | xargs kill -9  
    32.   
    33.  for pid in $fpms; do  
    34.  if echo $pid | egrep -q '^[0-9]+$'; then  
    35.  echo "PHP-FPM Pid $pid Kill"  
    36.  else  
    37.  echo "$pid IS Not A PHP-FPM Pid"  
    38.  fi  
    39.  done  
    40. }  
    41.   
    42. case $param in  
    43.  'start')  
    44.  start;;  
    45.  'stop')  
    46.  stop;;  
    47.  'restart')  
    48.  stop  
    49.  start;;  
    50.  *)  
    51.  echo "Usage: ./web.sh start|stop|restart";;  
    52. esac  
原文地址:https://www.cnblogs.com/lucky-man/p/6207882.html