Home > Backend Development > PHP Tutorial > Configure nginx+php7.1+fastcgi under mac os

Configure nginx+php7.1+fastcgi under mac os

不言
Release: 2023-03-24 18:34:02
Original
2091 people have browsed it

The content of this article is about configuring nginx php7.1 fastcgi under mac os. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

Mac os pre-installed The php version is 5.6.3. Use Homebrew to update php to php7.1 and build nginx.

Installationnginx

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

At this time, open localhost:8080 and you should be able to see: Welcome to nginx!

The basic commands of nginx are as follows:

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

Updatephp7.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
Copy after login

Modifynginx Configuration

1. After php7.1 is successfully installed, directly Accessing index.php may result in 403 or download. Need to modify the nginx.config file
Open the nginx.config file

$ vim /usr/local/etc/nginx/nginx.conf
Copy after login

2. Modify the user and user group (403 may appear on access because of the user and user group)

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

3. Add index.php

location / {
    root   html;    index  index.html index.htm index.php;
}
Copy after login

to the location configuration of the server. 4. Cancel the commented php part (delete the '#' in front of the code)

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;
}
Copy after login

5. Modify the scope of the previous step fastcgi_param parameter

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Copy after login

The above steps basically complete the configuration. I will add the virtual host part when I have time.

Related recommendations:

Configuring the PHP development environment through docker on Mac

The above is the detailed content of Configure nginx+php7.1+fastcgi under mac os. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template