首页  >  文章  >  后端开发  >  mac os下配置nginx+php7.1+fastcgi

mac os下配置nginx+php7.1+fastcgi

不言
不言原创
2018-05-18 10:26:551911浏览

这篇文章介绍的内容是关于mac os下配置nginx+php7.1+fastcgi,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

mac os 预装的php 版本 是 5.6.3,使用Homebrew将php更新到php7.1 并搭建 nginx。

安装 nginx

$ brew search nginx
$ brew install nginx
// 安装之后,常用的配置路径有:
// 配置文件路径:/usr/local/etc/nginx/nginx.conf
// 服务器默认路径:/usr/local/var/www
// 貌似是安装路径:/usr/local/Cellar/nginx/1.13.11

此时打开localhost:8080 应该是能看到 :Welcome to nginx!

nginx 的基本命令如下:

//测试nginx 站点是否正确
$ sudo nginx -t
//重新加载 nginx 服务
$ sudo nginx -s reload
// 关闭 nginx 服务
$ sudo nginx -s stop

更新 php7.1

$ brew update
// 更新安装 php7.1
$ brew install php71
$ echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.bash_profile
$ echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >> ~/.bash_profile
// 安装模块
$ brew install php71 --with-debug --with-homebrew-curl --with-homebrew-libxslt --with-homebrew-libressl --with-homebrew-libxml2 --with-phpbg --with-webp --with-imap --build-from-source php71-mcrypt php71-igbinary php71-mongodb php71-redis php71-intl  php71-xdebug

修改 nginx 配置

1、 php7.1安装成功之后,此时直接访问 index.php 可能会有 403 或者 下载 这两种情况。需要修改 nginx.config 文件
打开nginx.config文件

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

2、 修改用户和用户组(访问出现403可能是 因为用户和用户组)

user fg dev
// 在配置文件的第一行。user 后第一个参数是用户名,第二个是用户组。
// 查看用户和用户组 (系统偏好设置-->用户与群组-->选中用户右键-->高级选项)

3、 在server 的 location 配置中添加 index.php

location / {
    root   html;    index  index.html index.htm index.php;
}

4、 将被注释的php 部分 取消(将代码前面的‘#’删除)

location ~ \.php$ {
  root      html;
  fastcgi_pass  127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;  include    fastcgi_params;
}

5、 修改上一步范围内的 fastcgi_param 参数

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

以上步骤基本完成配置。等有空把虚拟主机部分再添加上。

相关推荐:

Mac上通过docker配置PHP开发环境

以上是mac os下配置nginx+php7.1+fastcgi的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn