首先brew安装前面文章上有的
安装nginx
brew install nginx
#启动nginx
sudo nginx
#测试配置是否有语法错误
sudo nginx -t
测试成功
如果不加sudo 会报如下错误:
添加开机启动
sudo vim /Library/LaunchDaemons/com.nginx.plist
在 /Library/LaunchDaemons/ 目录新建 com.nginx.plist 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//ENhttp://www.apple.com/DTDs/PropertyList-1.0.dtd ><plist version="1.0"><dict> <key>Label</key> <string>org.macports.nginx</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/nginx</string> </array> <key>KeepAlive</key> <true/></dict></plist>加载配置:launchctl load -w /Library/LaunchDaemons/com.nginx.plist
安装php7
brew install php71
php -v
启动php-fpm
sudo /usr/local/Cellar/php\@7.1/7.1.20/sbin/php-fpm -D
配置nginx
server {
listen 80; server_name localhost;location / {
root /usr/local/var/www; index index.html index.htm; }location ~ \.php$ {
root /usr/local/var/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/var/www$fastcgi_script_name; include fastcgi_params; }}
执行:
sudo vim /usr/local/var/index.php
<?php
echo phpinfo();
?>
我配置的是80端口运行
http://127.0.0.1/index.php
如有不懂,或者有其他错误需要解决请加群讨论