Mac 安装MNMP(Nginx1.10+PHP7.0)
安装Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
#加入Homebrew官方的几个软件源
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/php
安装PHP70(FPM方式)
brew install php70
因为OSX自带PHP环境,需要修改系统路径,优先运行brew安装的版本,在~/.bashrc中加入
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
安装PHP扩展
brew install php70-xdebug
#PHP-FPM的启动和关闭
php-fpm -D
killall php-fpm
#将php-fpm加入开机启动
ln -sfv /usr/local/opt/php70/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
安装Nginx
brew install nginx
#启动
nginx
#退出
nginx -s quit
#重启|重新打开|停止|退出
nginx -s reload|reopen|stop|quit
nginx安装后默认监听8080端口,通过http://localhost:8080 访问
#监听80端口需要root权限
sudo chown root:wheel /usr/local/Cellar/nginx/1.10.0/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.10.0/bin/nginx
#使用root权限启动Nginx
sudo nginx
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Nginx + PHP-FPM配置
mkdir -p /usr/local/var/logs/nginx
mkdir -p /usr/local/etc/nginx/sites
mkdir -p /usr/local/etc/nginx/conf.d
#编辑Nginx全局配置
vim /usr/local/etc/nginx/nginx.conf
# nginx.conf
worker_processes 1;
error_log /usr/local/var/logs/nginx/error.log debug;
pid /usr/local/var/run/nginx.pid;
events {
worker_connections 256;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" ' '"$http_x_forwarded_for" $host $request_time $upstream_response_time $scheme ' '$cookie_evalogin';
access_log /usr/local/var/logs/access.log main;
sendfile on; keepalive_timeout 65;
port_in_redirect off;
include /usr/local/etc/nginx/sites/*;
}
FastCGI的设置独立出来
vim /usr/local/etc/nginx/conf.d/php-fpm
location ~ \.php$ {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_intercept_errors on;
include /usr/local/etc/nginx/fastcgi.conf;
}
配置localhost
vim /usr/local/etc/nginx/sites/default
# default.conf
server {
listen 80;
server_name localhost;
root /opt/htdocs/;
location / {
index index.html index.htm index.php;
include /usr/local/etc/nginx/conf.d/php-fpm;
}
}
启动php-fpm和Nginx后可以通过
http://localhost 来运行php程序
安装MySQL
brew install mysql
#MySQL的启动和关闭
mysql.server start
mysql.server stop
#通过mysqladmin设置一个密码
mysqladmin -uroot password "123456"
#将MySQL加入开机启动
cp /usr/local/Cellar/mysql/5.7.12/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
设置启动别名
vim ~/.bash_profile
# nginx 启动
alias nginx.start='launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist'
# nginx 停止
alias nginx.stop='launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist'
# nginx 重启
alias nginx.restart='nginx.stop && nginx.start'
# php-fpm 启动
alias php-fpm.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist"
# php-fpm 停止
alias php-fpm.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist"
# php-fpm 重启
alias php-fpm.restart='php-fpm.stop && php-fpm.start'
# mysql 启动
alias mysql.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"
# mysql 停止
alias mysql.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"
# mysql 重启
alias mysql.restart='mysql.stop && mysql.start'