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

以前换电脑装了个Mnmp,有遇到一些小坑,写在这,但愿能帮到一些初次搭建Mnmp的phper。php

.
.
.html

安装 Mac 的包管理器 - homebrew

Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等不少实用的功能。mysql

安装Homebrew以前,须要肯定mac是否安装过xcode,而后安装xcode命令行工具。nginx

#安装xcode命令行工具
xcode-select --install

若是该方法你不肯用或者各类缘由,能够:git

登陆 [https://developer.apple.com/download/more/][1] 而后下载 dmg 安装

注:必定要选择和mac系统版本,xcode版本一致的命令行工具。github

好了如今咱们开始安装Homebrew。sql

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

安装好了Homebrew以后,即可以使用brew命令来安装相应的包了。apache

Nginx

brew install nginx

执行完以后Nginx就安装好了,如下为nginx几个经常使用命令。vim

# 启动 nginx服务
sudo nginx

# 从新加载配置|重启|中止|退出 nginx
nginx -s reload|reopen|stop|quit

#测试配置是否有语法错误
nginx -t
# 启动 nginx
sudo ngixn -c /usr/local/etc/nginx/nginx.conf

#测试配置是否有语法错误
nginx -t -c /usr/local/etc/nginx/nginx.conf

nginx启动后,在浏览器中输入http://localhost:8080/,回车便可看到运行结果,显示的是/usr/local/Cellar/nginx/1.10.0/html/index.html文件的内容。xcode

设置开机自启动nginx服务设置:

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

MySQL

brew install mysql
#启动mysql
/usr/local/Cellar/mysql/5.7.12/bin/mysqld
#设置密码
/usr/local/bin/mysqladmin -u root password 'new-password'
#登陆mysql
mysql -u root -p

设置开机启动

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

PHP

brew tap homebrew/php #php扩展
brew install --without-apache --with-fpm --with-mysql php56 ## php-fpm

php设置开机启动

mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

配置 Nginx

vim /usr/local/etc/nginx/nginx.conf

#隐藏入口文件配置
location / {
   index  index.php index.html index.htm;
   if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php?$1 last;    #ci框架写法
        #rewrite ^/(.*)$ /index.php?s=/$1 last;    #tp框架写法
        break;
   }
}

修改host

vim /etc/hosts
# 127.0.0.1 www.test.com #
相关文章
相关标签/搜索