一、安装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
二、安装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 ..
2. 安装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
<!--<value name="user">nobody</value>-->
Unix group of processes
<!--<value name="group">nobody</value>-->
修改为:
Unix user of processes
<value name="user">www</value>
Unix group of processes
<value name="group">www</value>
启动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
三、常见问题:
问题: nginx ./configure时报如下错误./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
解决:这是由于未PCRE库,请安装PCRE库在运行./configure。也可以使用带--without-http_rewrite_module参数进行./configure,但是这将导致nginx不支持rewrite功能!
四、相关文件下载地址:
libcurl: http://curl.haxx.se/download.html
libxml2: ftp://xmlsoft.org/libxml2/
libxslt: ftp://xmlsoft.org/libxml2/
libpng: http://www.libpng.org/pub/png/libpng.html
libjpeg: http://ijg.org/files/
freetype:http://download.savannah.gnu.org/releases/freetype/
pcre:http://www.pcre.org/
nginx:http://nginx.org/en/download.html
php-fpm:http://php-fpm.org/
php5:http://www.php.net/releases/
MySQL:http://www.mysql.com/downloads/mirror.php?id=404683#mirrors
发表评论 取消回复