首頁  >  文章  >  後端開發  >  mac os下配置nginx+php7.1+fastcgi

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

不言
不言原創
2018-05-18 10:26:552001瀏覽

這篇文章介紹的內容是關於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