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

发布时间:2019-08-07 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Mac下Nginx、PHP、MySQL 和 PHP-fpm安装配置脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

之前换脑装了个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 #

脚本宝典总结

以上是脚本宝典为你收集整理的Mac下Nginx、PHP、MySQL 和 PHP-fpm安装配置全部内容,希望文章能够帮你解决Mac下Nginx、PHP、MySQL 和 PHP-fpm安装配置所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。