![](/api/file/getImage?fileId=5de9444de8ede66f0c000020) 工作的需要,要使用nginx,那系统自带的apache就没用了,不想让它占据我富贵的硬盘空间,所以,就开始折腾着干掉它了。 ## 停止内置Apache服务器 ``` sudo apachectl -k stop sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist ``` ## 删除的文件列表 ``` sudo rm -rf /usr/sbin/httpd sudo rm -rf /usr/sbin/httpd-wrapper sudo rm -rf /usr/sbin/apachectl sudo rm -rf /usr/libexec/apache2 sudo rm -rf /etc/apache2 ``` ## 安装Nginx ``` brew install nginx ``` 耐心的等待,装完以后: ``` 默认的根目录:/usr/local/var/www 默认的端口:8080 配置文件:/usr/local/etc/nginx/nginx.conf 其它配置文件:/usr/local/etc/nginx/servers/ 启动:brew services start nginx ``` ## 启用系统自带的php-fpm ``` cd /etc sudo mv php-fpm.conf.default php-fpm.conf cd php-fpm.d sudo mv www.conf.default www.conf ``` 修改/etc/php-fpm.conf中的errorlog为 ``` error_log = /usr/local/var/log/php-fpm.log ``` 尝试输入 ``` php-fpm ``` 查看是否正常启动。 ## php-fpm自启动 vi ~/Library/LaunchAgents/phpfpm.plist 内容如下: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>KeepAlive</key> <true/> <key>Label</key> <string>phpfpm</string> <key>ProgramArguments</key> <array> <string>/usr/sbin/php-fpm</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> ``` ## Nginx添加php支持 注释掉nginx.conf中server段,新建一个文件 vi /usr/local/etc/nginx/servers/default 文件内容如下: ``` server { listen 80; server_name localhost; root /Volumes/Workarea/usr/htdocs/; location / { index index.html index.htm index.php; include /usr/local/etc/nginx/php-fpm.conf; } } ``` vi /usr/local/etc/nginx/php-fpm.conf 文件内容如下: ``` location ~ \.php$ { try_files $uri = 404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_intercept_errors on; include /usr/local/etc/nginx/fastcgi.conf; } ``` 最后修改:6年前 © 著作权归作者所有