Mac下使用brew搭建PHP7+nginx+mysql开发环境

时间:2021-07-21 20:32:51

http://blog.csdn.net/mysteryhaohao/article/details/52230634

 

HomeBrew

brew的安装,直接上官网:http://brew.sh/ 

一个命令就搞定:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

 

PHP7

安装好brew之后,先安装php7。安装php7之前,要先更新一下brew的源并加入一些第三方的库:

brew update

brew tap homebrew/dupes

brew tap homebrew/versions

brew tap homebrew/homebrew-php

然后就可以使用brew搜索php70的包并安装了

brew search php70

brew install php70

至于php70的扩展安装,在search的时候就已经有扩展的列表的,按需安装,安装也很简单:

brew install php70-redis

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/7.2/

To have launchd start php now and restart at login:
  brew services start php
Or, if you don't want/need a background service you can just run:
  php-fpm

 

Nginx

同php7一样:

brew install nginx

安装好后,如果要加入到自启动的话,要先添加一个文件夹:

mkdir -p ~/Library/LaunchAgents

然后把自启动的plist加入到这个文件夹内:

cp /usr/local/Cellar/nginx/1.10.1/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents

然后执行mac的launchctl命令就可以了:

launchctl -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

如果把php也加入自启动的话,也是一样的吧Cellar/php下面的plist加入到LaunchAgents文件夹下并执行launchctl命令即可

 

Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:
  brew services start nginx
Or, if you don't want/need a background service you can just run:
  nginx

 

Mysql

安装一样简单:

brew install mysql

安装好之后,执行mysql.server start

这时候要记得,使用mysql_secure_installration来对mysql进行安全设置,包括设置root密码以及密码安全级别等

  We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start