Linux/Unix系統下nginx+php安裝簡明教程

本文轉載自Linux/Unix系統下nginx+php安裝簡明教程,請保留轉載信息~php

 1、安裝nginx:css

1. 安裝pcre庫,nginx的rewrite模板需用到pcre庫:html

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:mysql

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. 新建用戶和組:linux

groupadd www
useradd -r -g www www

本文出自 Linux/Unix系統下nginx+php安裝簡明教程nginx

 2、安裝PHP5 

1. 安裝依賴包:sql

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:app

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:curl

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
<!–<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

  更多文章請訪問:愛E族計算機網絡技術博客

相關文章
相關標籤/搜索