1、关闭并删除系统自带的apache
sudo apachectl stop #关闭apache,如果事先没开启过,可以忽略报错信息
sudo rm /usr/sbin/apachectl
sudo rm /usr/sbin/httpd
sudo rm -r /etc/apache2/
sudo rm -r /usr/bin/php
3、安装 Command Line Tools
xcode-select --install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
brew update
brew upgrade
brew tap homebrew/dupes
brew tap homebrew/php
brew install php56 --without-apache --with-fpm --with-mysql
添加自启动
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents
为了后面管理方便,将命令 alias 下
nano ~/.bash_aliases
alias php-fpm.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist"
alias php-fpm.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist"
alias php-fpm.restart='php-fpm.stop && php-fpm.start'
nano ~/.bash_profile
[[ -f ~/.bash_aliases ]] && . ~/.bash_aliases
source .bash_profile //更新文件
这样就可以用快捷命令来管理php-fpm了
php-fpm.start
php-fpm.stop
php-fpm.restart
brew install php56-redis
brew install php56-amqp
brew install nginx
配置nginx
nano /usr/local/etc/nginx/nginx.conf
<pre name="code" class="html">user wby staff;
worker_processes 1;
events {
worker_connections 128;
}
http {
include mime.types;
include vhost/*.conf;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
}
添加vhost
mkdir
/usr/local/etc/nginx/vhost
nano /usr/local/etc/nginx/vhost/default.conf
server {
listen 80;
server_name zjy;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /Users/wby/Documents/PHPProjects/operator_sz_web/public;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /Users/wby/Documents/PHPProjects/public;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /Users/wby/Documents/PHPProjects/operator_sz_web/public$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}
}
nginx //启动
nginx -s stop //停止
nginx -s reload //重新加载
【数据库是直接连的服务器,所以我就不装mysql了】
参考了以下内容:
http://tabalt.net/blog/install-nginx-mysql-php-fpm-by-brew-on-mac/
http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/