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

本文详细介绍了如何在Mac环境中使用Homebrew安装并配置Mnmp环境,包括Nginx、MySQL及PHP的安装步骤与配置方法,并提供了设置服务自启动的具体指令。

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

.
.
.

安装 Mac 的包管理器 - homebrew

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

安装Homebrew之前,需要确定mac是否安装过xcode,然后安装xcode命令行工具。

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

如果该方法你不愿用或者各种原因,可以:

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

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

好了现在我们开始安装Homebrew。

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

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

Nginx

brew install nginx

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

# 启动 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文件的内容。

设置开机自启动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 #
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值