Nginx 配置集成 php-fpm

nginx

下载nginx二进制包。
编译参数

./configure --prefix=/var/local/nginx
  • nginx 编译需要先安装 openssl , pcre zlib
  • prefix 指定nginx 的安装路径 ,不指定默认为 /usr/local

nginx.conf 中配置 php, 在prefix选项指定的安装路径中conf目录下。

增加配置,在server段下

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
#  
location ~ \.php$ {  
root html;  
fastcgi_pass 127.0.0.1:9000;  
fastcgi_index index.php;  
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  
include fastcgi_params;  
}

php

下载php 二进制包
编译参数

./configure --prefix=/usr/local/php  --enable-fpm --with-mcrypt \
--enable-mbstring --disable-pdo --with-curl --disable-debug  --disable-rpath \
--enable-inline-optimization --with-bz2  --with-zlib --enable-sockets \
--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \
--with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli \
--with-gd --with-jpeg-dir
  • php 编译需要 oniguruma
  • php 配置文件路径 安装路径下 lib文件夹中

配置 php-fpm

  1. php-fpm 配置文件, 安装馋包中提供了php-fpm的默认配置, 以.default 结尾,因此需要重命名,
# 在php安装路径下,也就是前面 --prefix选项指定的值
cp etc/php-fpm.conf.default etc/php-fpm.con
# php-fpm 引用了 etc/php-fpm.d 中的以.conf 结尾的配置文件
# 这个也是在php安装路径下
cp etc/php-fpm.d/www.conf.default etc/php-fpm.d/www.conf
  1. 在www.conf文件中配置用户
  • 先新建用户
sudo groupadd www-data
sudo useradd -g www-data www-data
  • www.conf 配置文件中指定用户 ,默认配置用户 是nobody
user = www-data
group = www-data

启动测试

php 测试文件

在 nginx安装目录下html 目录下,新建index.php


启动 php-fpm

在 php安装目录下 sbin目录下

./php-fpm

启动nginx

在nginx安装目录下sbin 目录下

./nginx 

浏览器访问

http://localhost:80/index.php

你可能感兴趣的:(Nginx 配置集成 php-fpm)