fastcgi 配置 php,Nginx + PHP(FastCGI)安装配置详解

本文主要和大家分享Nginx + PHP(FastCGI)安装配置笔记,希望能帮助到大家。

软件环境:CentOS 5.7 + PHP 5.2.17 + Nginx 0.8.55

1. 编译安装 PHP 和 PHP-FPM

提示:

安装PHP前应先安装MySQL,具体方法请自行baidu或google;

PHP所需支持库的安装这里不做过多介绍,可上网搜索参照相关教程进行安装。从http://php-fpm.org/downloads/下载与当前PHP版本对应的PHP-FPM源码包,例如:php-5.2.17-fpm-0.5.14.diff.gz

tar zxvf php-5.2.17.tar.gz

gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1

cd php-5.2.17

./configure –prefix=/usr/local/php/ –with-config-file-path=/usr/local/php/etc –with-mysql=/usr/local/mysql/ –with-pdo-mysql=/usr/local/mysql/ –with-gd –with-zlib –with-curl –with-jpeg-dir –with-png-dir –with-libxml-dir –with-freetype-dir –with-iconv=/usr/local –with-mcrypt –enable-fastcgi –enable-fpm –enable-xml –enable-mbstring

make

make install

cp php.ini-dist /usr/local/php/etc/php.ini

注意:上面配置PHP编译参数中的–enable-fastcgi是必须开启的。

2. 创建 Nginx 使用的用户和用户组groupadd www

useradd -g www www

3. 创建站点目录并设置权限mkdir -p /htdocs/www

chmod +w /htdocs/www

chown -R www:www /htdocs/www

4. 安装 Nginx 所需的 PCRE 库tar zxvf pcre-8.13.tar.gz

cd pcre-8.13

./configure

make

make install

5. 安装 Nginxtar zxvf nginx-0.8.55.tar.gz

cd nginx-0.8.55

./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –user=www –group=www

make

make install

6. 配置 Nginx,创建虚拟主机

在 nginx.conf 文件的 http{…} 段中,增加一个 server{…} 段,例如下面的代码:server {

listen 80;

server_name www.youdomain.com; #你的域名

root /htdocs/www;

access_log logs/www.access.log;

location / {

index index.html index.php;

}

error_page 500 502 503 504  /50x.html;

location = /50x.html {

root html;

}

location ~ .*\.php?$ {

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

include        fastcgi.conf;

}

location ~ /nginx_info {

access_log off;

stub_status on;

}

}

注意:上面的配置中,增加了location ~ /nginx_info {…},这样就可以通过http://www.youdomain.com/nginx_info/来查询Nginx的状态信息了。

启动 PHP-FPM

/usr/local/php/sbin/php-fpm start

启动 Nginx

/usr/local/nginx/sbin/nginx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值