Mac 下 Nginx、PHP、MySQL 和 PHP-fpm 的安装和配置

安装 Mac 的包管理器 - homebrew

home-brew?home-brew与OS X就像nodes与npm,php与composer,apt-get与Ubutun,yum与centos

安装Homebrew之前,先安装xcode命令行工具

xcode-select –install

home-brew的安装很容易,只要你的客户终端安装了ruby即可,其实,你一点都不用担心此事,OS X系统已经预装了ruby。

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

安装 Nginx 服务器

安装好了Homebrew之后,便可以使用brew命令来安装相应的包了。接下来,安装nginx服务器。

brew install nginx

安装完成后执行下面几条命令测试一下

1
2
3
4
5
6
###### 启动 nginx服务
sudo nginx
# 重新加载配置|重启|停止|退出 nginx
nginx -s reload|reopen|stop|quit
#测试配置是否有语法错误
nginx -t

nginx启动后,在浏览器中输入http://localhost:8080/,回车即可看到运行结果

开机自启动nginx服务设置:

1
2
3
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/nginx/1.10.0/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

nginx权限

1
2
sudo chown root:wheel /usr/local/Cellar/nginx/1.10.0/sbin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.10.0/sbin/nginx

安装和配置 MySQL 服务器

brew install mysql

查看mysql数据库是否启动

ps -ef | grep mysql

如果没有启动,使用安装的mysql目录下的mysqld命令启动mysql:

/usr/local/Cellar/mysql/5.7.12/bin/mysqld

可直接使用/usr/local/bin/mysqld就可以启动

which mysqld

设置开机启动mysql

mkdir -p ~/Library/LaunchAgents/
cp /usr/local/Cellar/mysql/5.7.12/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

安装php56和php-fpm

php的安装很简单,php-fpm目前已经集成到php的内核

brew install php56 –with-imap –with-tidy –with-debug –with-pgsql –with-mysql –with-fpm

安装php扩展

1
2
3
4
5
brew install php56-apcu php56-intl php56-redis php56-uuid php56-zookeeper
php56-thrift php56-solr php56-ssh2 php56-gmagick php56-kafka php56-libevent
php56-imagick php56-msgpack php56-geoip php56-mcrypt php56-swoole
php56-scrypt php56-xdebug php56-yaf php56-yaml php56-xhprof
php56-memcache php56-memcached php56-gearman