本文转载自Linux/Unix系统下nginx+php安装简明教程,请保留转载信息~

 一、安装nginx:

1. 安装pcre库,nginx的rewrite模板需用到pcre库:

mkdir -p /works
cd /works
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.20.tar.gz
tar -zxvf pcre-8.20.tar.gz
./configure
make && make install
cd ..

2. 安装nginx:

wget http://nginx.org/download/nginx-1.0.10.tar.gz
tar -zxvf nginx-1.0.10.tar.gz
cd nginx-1.0.10
./configure
make && make install
cd ..

3. 新建用户和组:

groupadd www
useradd -r -g www www

本文出自 Linux/Unix系统下nginx+php安装简明教程

 二、安装PHP5 

1. 安装依赖包:

libcurl:
wget http://curl.haxx.se/download/curl-7.23.1.tar.gz
tar -zxvf curl-7.23.1.tar.gz
cd curl-7.23.1/
./configure
make && make install
cd ..

libxml2:

wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz
tar -zxvf libxml2-2.7.6.tar.gz
cd libxml2-2.7.6
./configure
make && make install
cd ..

libxslt:

wget ftp://xmlsoft.org/libxml2/libxslt-1.1.24.tar.gz
tar -zxvf libxslt-1.1.24.tar.gz
cd libxslt-1.1.24
./configure  make && make install
cd ..

freetype:

wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.6.tar.gz
tar -zxvf freetype-2.4.6.tar.gz
cd freetype-2.4.6  ./configure
make && make install
cd ..

libpng:

wget "http://prdownloads.sourceforge.net/libpng/libpng-1.5.6.tar.gz?download"
tar -zxvf libpng-1.5.6.tar.gz
cd libpng-1.5.6  ./configure
make && make install
cd ..

libjpeg:

wget http://ijg.org/files/jpegsrc.v8c.tar.gz
tar -zxvf jpegsrc.v8c.tar.gz
cd jpeg-8c/
./configure
make && make install
cd ..

本文出自 Linux/Unix系统下nginx+php安装简明教程

安装php5和php-fpm:

wget http://museum.php.net/php5/php-5.2.16.tar.gz
wget http://php-fpm.org/downloads/php-5.2.16-fpm-0.5.14.diff.gz
tar -zxvf php-5.2.16.tar.gz
gunzip php-5.2.16-fpm-0.5.14.diff.gz
cd php-5.2.16/
patch -p1 < ../php-5.2.16-fpm-0.5.14.diff
./configure \
–with-curl \
–enable-calendar \
–with-xsl \
–with-libxml-dir \
–enable-ftp \
–with-gd \
–with-freetype-dir \
–with-jpeg-dir \
–with-png-dir \
–enable-mbstring \
–with-zlib \
–enable-shared \
–with-mysql \
–enable-fastcgi \
–enable-fpm
./configure && make && make install

修改php-fpm的配置文件/usr/local/etc/php-fpm.conf,设置执行php-fpm的用户和组名:
大约在第62行:

 

Unix user of processes
nobody–>
Unix group of processes
nobody–>

修改为:

Unix user of processes
www
Unix group of processes
www

启动php-fpm:

/usr/local/sbin/php-fpm start
lsof -i:9000
netstat -ant|grep 9000
#9000为php-fpm的默认端口,可以在/usr/local/etc/php-fpm.conf中修改。

修改nginx配置文件/usr/local/nginx/conf/nginx.conf,我的nginx配置文件如下:

worker_processes  10;
events {
worker_connections  1024;
}
http {
include       mime.types;
default_type  application/octet-stream;
sendfile        on;
keepalive_timeout  65;
gzip  on;
server {
listen       80;
server_name  ead;
root /data/faceshow/www;
location / {
root   html;
index  index.php index.html index.htm;
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}
#此段代码为关键
location  ~ \.php$ {
fastcgi_pass   127.0.0.1:9000; #对应php-fmp的端口
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /data/faceshow/www/$fastcgi_script_name;
#php文件的物理路径
include        fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires      30d;
}
location ~ .*\.(js|css)?$
{
expires      1h;
}
}
}

启动nginx:

/usr/local/nginx/bin/nginx
/usr/local/nginx/bin/nginx -s reload

  更多文章请访问:爱E族计算机网络技术博客