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
<?php
echo phpinfo();exit();
?>
8.啟動服務(wù)
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