I was built in the CENTOS5 environment of the Nginx server, using the PHP-FPM way to drive PHP, the following description of the use of the configuration process.
Environment:
Operating system: CentOS 5
nginx-1.0.12
php-5.3.10
1. Install php-5.3.10
Note: PHP-FPM has been added as a module to the PHP code, which only needs to be added when PHP is compiled
--enable-fpm
wget http://cn.php.net/distributions/php-5.3.10.tar.gz
TAR-ZXVF php-5.3.10.tar.gz
CD php-5.3.10
./configure--prefix=php-root--enable-fastcgi--with-mysql=/home/programs/mysql--enable-zend-multibyte- Enable-zip--enable-discard-path--enable-force-cgi-redirect--with-libxml-dir--with-curl--with-openssl-- With-mysqli--with-zlib--enable-mbstring--with-gd--with-mcrypt--enable-exif-- Enable-force-cgi-redirect--enable-pdo--with-pdo-mysql=/home/programs/mysql--with-ttf--with-iconv--enable-xml-- WITH-GD--with-jpeg-dir=/usr/local/ --with-png-dir=/usr/local--with-freetype-dir=/usr/include/freetype2/
Make make
Install
After the installation is complete, create a new php.ini file in php-root/lib/, and you can modify some configuration items
Note: The above configuration needs to be modified according to the needs of the environment, including the GD library, MySQL, PHP-FPM and other configuration
2. Install nginx-1.0.12
May need to rely on:
Module dependencies:
Gcc
Gzip--Zlib
Rewrite--Pcre
SSL--OpenSSL
Yum install gcc gcc-c++ autoconf automake
yum-y install zlib zlib-devel
yum-y
install OpenSSL openssl-devel Yum-y Install Pcre Pcre-devel
Download Installation Nginx
wget http://nginx.org/download/nginx-1.0.12.tar.gz
tar-zxvf nginx-1.0.12.tar.gz
cd nginx-1.0.12
./ Configure--prefix=nginx-root make
3. Configure PHP-FPM
First copy the configuration file and edit it
CP phproot/etc/php-fpm.conf.default-> phproot/etc/php-fpm.conf
VI phproot/etc/php-fpm.conf
Here you only need to modify the user and the port you want to monitor
; Unix User/group of Processes
; Note:the user is mandatory. If The group is not set, the default user ' s group
; would be used.
user = WebAdmin
group = WebAdmin
; The address in which to accept FastCGI requests.
; Valid syntaxes are:
; ' Ip.add.re.ss:port ' -to listen in a TCP socket to a specific address
; A specific port;
; ' Port ' -to listen on a TCP socket to all addresses on a
; specific port;
; ' /path/to/unix/socket '-To listen on a UNIX socket.
; Note:this value is mandatory.
Listen = 127.0.0.1:9000
Can be optimized according to the requirements
4. Make FPM Start service
Copy the following code, VI/ETC/INIT.D/PHP-FPM, save
Modify executable Permissions chmod +X/ETC/INIT.D/PHP-FPM
Start/ETC/INIT.D/PHP-FPM Start
Stopping/etc/init.d/php-fpm stop
Restart/ETC/INIT.D/PHP-FPM restart
#!/bin/bash # php-fpm Startup script for PHP-FPM, a FastCGI implementation # This script is created by Tony at 2010.0
7.21, based on Jackbillow ' s nginx script.
# It is v.0.0.1 version.
# If you are errors on this scripts,please contact Tony.
# by sending mail to Tonytzhou at gmail dot com. # Chkconfig:-DESCRIPTION:PHP-FPM is a alternative FastCGI implementation, with some additional features
Useful for sites of any size, especially busier sites. # # PROCESSNAME:PHPFPM # pidfile:/usr/local/var/run/phpfpm.pid # config:/usr/local/etc/phpfpm.conf phpfpm=/h OME/PROGRAMS/PHP/SBIN/PHP-FPM Config=/home/programs/php/lib/php.ini pid=/home/programs/php/run/php-fpm.pid RETVAL
=0 prog= "PHPFPM" # Source function library. .
/etc/rc.d/init.d/functions # Source Networking configuration. .
/etc/sysconfig/network # Check that networking are up. [${networking} = "No"] && exit 0 [-x $phpfpm] | | Exit 0 # StArt PHPFPM daemons functions. Start () {if [e $pid];then Echo phpfpm is already running ... "Exit 1 fi echo-n $" starting $
Prog: "Daemon $phpfpm-C ${config} retval=$?" echo [$RETVAL = 0] && touch/var/lock/subsys/phpfpm return $RETVAL} # Stop phpfpm daemons F
Unctions.
Stop () {echo-n $ "stopping $prog:" Killproc $phpfpm retval=$? echo [$RETVAL = 0] && rm-f/var/lock/subsys/phpfpm/var/run/phpfpm.pid} # Reload PHPFPM servi
CE functions.
Reload () {echo-n $ "reloading $prog:" #kill-hup ' cat ${pid} ' Killproc $phpfpm-hup retval=$?
echo} # We were called.
Case "in Start" start;;
stop) stop;;
reload) reload;;
restart) stop start;;
Status) Status $prog Retval=$?
;; * echo $ "Usage: $prog {start|stop|restart|reload|status|help}" Exit 1 Esac Exit $RETVAL
5. Configure Nginx
Use 80 port, domain name is www.demo.com
#user nobody;
User WebAdmin WebAdmin;
Worker_processes 4;
#error_log Logs/error.log;
#error_log Logs/error.log Notice;
#error_log Logs/error.log Info;
PID Logs/nginx.pid;
# Specifies the number of file descriptors Worker_rlimit_nofile 51200;
Events {# Using the network I/O model, Linux recommended using Epoll, FRESSBSD recommended private kqueue use Epoll;
# Allow links number worker_connections 51200;
} http {include mime.types;
Default_type Application/octet-stream; Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" "$status $body _bytes_sen
T "$http _referer" "$http _user_agent" "$http _x_forwarded_for";
Access_log Logs/access.log Main;
#autoindex off;
# set the character set, if a variety of character sets, do not set #charset utf-8;
Sendfile on;
Keepalive_timeout 65;
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300; Fastcgi_buffer_size 64K
Fastcgi_buffers 4 64k;
Fastcgi_busy_buffers_size 128k;
Fastcgi_temp_file_write_size 128k;
#开启gzip gzip on;
Gzip_min_length 1k;
Gzip_buffers 4 16k;
Gzip_http_version 1.1;
Gzip_com_level 2;
Gzip_types text/plain text/css application/x-javascript text/xml application/xml;
Gzip_vary on;
server {Listen 80;
server_name www.demo.com;
Index index.html index.htm index.php;
Root Web-root; # picture cache location ~* \.
(?: ico|gif|jpe?g|png|bmp|swf) $ {# Some basic Cache-control for static files to is sent to the browser
Expires Max;
Add_header Pragma public;
Add_header Cache-control "Public, must-revalidate, proxy-revalidate"; # static Resource cache location ~.*\.
(JS|CSS)? $ {Expires 1h; } error_page 502 503 504/50x.html;
Location =/50x.html {root html;
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 #
Location ~ \.php$ {root web-root; Fastcgi_pass 127.0.0.1:9000;
# FPM Listening ports and IP fastcgi_index index.php;
Fastcgi_param Script_filename Web-root$fastcgi_script_name;
Include Fastcgi_params; }
}
}
Save nginx.conf after configuration.
6. Start Nginx
Nginx-root/bin/nginx-c nginx-root/conf/nginx.conf
You can visit http://www.demo.com.
Note: www.demo.com need to be bound to the hosts