[学习笔记]mac配置nginx+laravel+php-fpm

首先先安装好brew,接下来
安装nginx

1
$brew install nginx

打开nginx

1
$nginx

nginx
重新加载|重启|停止|退出 nginx

1
$nginx -s reload|reopen|stop|quit

安装php

1
2
3
4
5
6
7
8
9
10
11
12
13
$brew tap homebrew/dupes
$brew tap josegonzalez/homebrew-php
$brew install php56
--with-debug
--with-fpm
--with-gmp
--with-homebrew-openssl
--with-imap --with-intl
--with-libmysql
--without-bz2
--without-mysql
--without-p:qcntl
--without-pear

5.1版的laravel需要php>=5.5.9,建议直接更新至php5.6

nginx配置
修改/usr/local/etc/下的nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
server {

listen 你的端口号;
server_name 你的域名;
set $root_path '你的laravel项目路径,记得加上/public';
root $root_path;

index index.php index.html index.htm;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php {

fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;

include fastcgi_params;

fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}

location ~ /\.ht {
deny all;
}
}

启动php-fpm

1
$sudo php-fpm

因为nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器(PHP-fpm)处理,并把结果返回给客户端。

如果你的laravel项目时从git仓库里clone下来的,需要先composer install一下,它的使命就是帮你为项目自动安装所依赖的开发包,否则会找不到vendor文件。

如果提示”Mcrypt PHP extension required”(老版本laravel),则需要下载mcrypt:brew install mcrypt。

1
$brew install php56-mcrypt