大刘的 iOS 自学笔记

MacOS nginx & php

2018-10-07  本文已影响48人  大刘

Mac上安装homebrew

安装完成后位置 :
/usr/local/Homebrew/

出现错误:
Already downloaded: /Users/.....a.tar...
解决方法:删除:rm -rf /Users/.....a.tar...

Mac上安装ngnix

brew update
brew search nginx // 查询要安装的软件是否存在
brew info nginx // 查看要安装的软件信息
brew install nginx

Warning: homebrew/core is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/core)" fetch --unshallow

按照提示在控制台键入: git -C "$(brew --repo homebrew/core)"

Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service you can just run:
nginx

...

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

开启nginx: nginx
关闭nginx: nginx -s stop


参考链接:https://blog.csdn.net/u011061889/article/details/76795555

nginx对接Php

PHP配置
nginx不同于apache, nginx只支持fastcgi协议。因此对于PHP,需要启动php-fpm(是一个PHPFastCGI管理器)
这里我们使用MAC自带的PHP:
首先copy一份php-fpm配置文件:
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf

然后修改这个copy后的php-fpm.conf文件中的error_log:

error_log = /usr/local/var/log/php-fpm.log

nginx配置
/usr/local/etc/nginx/nginx.conf

$php-fpm
ERROR:failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory..

错误的原因是php-fpm会读取路径为/private/etc/php-fpm.conf的配置文件,而此文件不存在。

解决方法:
cp /private/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
复制好这个文件之后需要修改这个php-fpm.conf文件中的一些东西:

...
; Note: the default prefix is /usr/var
; Default Value: log/php-fpm.log
error_log = log/php-fpm.log
...

注意这里面有一个error_log,默认目录是/usr/var/...,但是在mac目录下没有这样一个路径,因此如果这时候运行php-fpm会报错:

`$ php-fpm --fpm-config /usr/local/etc/php-fpm.conf`  
ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory    

我们可以把这句配置代码修改一下:

error_log = /usr/local/var/log/php-fpm.log

同理,把pid也修改一下:

pid = /usr/local/var/run/php-fpm.pid

注意这个配置文件的最后一行是: include=/private/etc/php-fpm.d/*.conf
即会读取/private/etc/php-fpm.d/目录下所有以.conf后缀的文件,而.conf文件也是不存在的,因此我们直接拷贝一份/private/etc/php-fpm.d/www.conf.default为/private/etc/php-fpm.d/www.conf即可。

运行:
$ php-fpm --fpm-config /usr/local/etc/php-fpm.conf
如果出现错误:
ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address 
这说明127.0.0.1:9000已被绑定,可以通过命令 killall php-fpm 解决

上一篇下一篇

猜你喜欢

热点阅读