Mac安装nginx 以及搭建php环境

1.安装nginx

brew install nginx


2.修改php-fpm文件

sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf


3.修改error的log地址

vim打开 /private/etc/php-fpm.conf,将error_log地址改为

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


4.给nginx的server的location加上index.php

vim打开 /usr/local/etc/nginx/nginx.conf,添加index.php

location / {

root  html;

index  index.html index.htm index.php;

}


5.打开location~.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;

}


6.修改fastcgi_param

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

改为

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;


7.新建测试文件

在/usr/local/var/www 目录下新建index.php

echo phpinfo();exit();

?>


8.启动服务

sudo nginx

sudo php-fpm


PS:会报如下错误:

[14-Dec-2017 22:40:11] WARNING: Nothing matches the include pattern '/private/etc/php-fpm.d/*.conf' from /private/etc/php-fpm.conf at line 125.

[14-Dec-2017 22:40:11] ERROR: No pool defined. at least one pool section must be specified in config file

[14-Dec-2017 22:40:11] ERROR: failed to post process the configuration

[14-Dec-2017 22:40:11] ERROR: FPM initialization failed

把 /private/etc/php-fpm.d/ 目录下的www.conf.default改为www.conf即可

sudo mv www.conf.default www.conf

你可能感兴趣的:(Mac安装nginx 以及搭建php环境)