- 论坛徽章:
- 0
|
三、编译安装PHP及Nginx
1.PHP(Fastcgi)编译安装
1)php-fpm 给PHP(Fastcgi)打补丁
#tar xvf php-5.2.6.tar.bz2
#gzip -cd php-5.2.6-fpm-0.5.8.diff.gz | patch -d php-5.2.6 -p1
2)PHP(Fastcgi)安装.
#cd php-5.2.6
#vi in_php5.sh
./configure \
"--prefix=/usr/local/php-fcgi" \
"--enable-fastcgi" \
"--enable-fpm" \
"--enable-discard-path" \
"--enable-force-cgi-redirect" \
"--with-config-file-path=/usr/local/php-fcgi/etc" \
"--enable-zend-multibyte" \
"--with-mysql=/usr/local/mysql" \
"--with-libxml-dir" \
"--with-iconv-dir=/usr/lib" \
"--with-xmlrpc" \
"--with-gd=/usr/local/gd2" \
"--with-jpeg-dir" \
"--with-png-dir" \
"--with-bz2" \
"--with-freetype-dir" \
"--with-zlib-dir " \
"--with-openssl=/usr/local/openssl" \
"--with-mcrypt=/usr/local/libmcrypt" \
"--enable-sysvsem" \
"--enable-inline-optimization" \
"--enable-soap" \
"--enable-gd-native-ttf" \
"--enable-ftp" \
"--enable-mbstring" \
"--enable-exif" \
"--disable-debug" \
"--disable-ipv6"
make && make install
cp php.ini-dist /usr/local/php-fcgi/etc/php.ini
#sh in_php5.sh
4)安装Xcache
tar xvf xcache-1.2.2.tar.gz
cd xcache-1.2.2
#vi in_xcache.sh
/usr/local/php-fcgi/bin/phpize
./configure --enable-xcache --enable-xcache-coverager --with-php-config=/usr/local/php-fcgi/bin/php-config \
--enable-inline-optimization --disable-debug
make && make install
#sh in_xcache.sh
#vi /usr/local/php-fcgi/etc/php.ini #编辑php.ini在其内容最后加入如下内容:
[xcache-common]
zend_extension = /usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-20060613/xcache.so
[xcache.admin]
xcache.admin.user = "admin"
;如何生成md5密码: echo -n "password"| md5sum
xcache.admin.pass = "035d849226a8a10be1a5e0fec1f0f3ce" #密码为52netseek
[xcache]
; Change xcache.size to tune the size of the opcode cache
xcache.size = 24M
xcache.shm_scheme = "mmap"
xcache.count = 4
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
; Change xcache.var_size to adjust the size of variable cache
xcache.var_size = 8M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
[xcache.coverager]
xcache.coverager = On
xcache.coveragedump_directory = ""
4)安装Memcache
cd memcache-2.2.3
#vi in_memcache.sh
/usr/local/php-fcgi/bin/phpize
./configure --with-php-config=/usr/local/php-fcgi/bin/php-config
make && make install
#sh in_memcache.sh
5) PHP初始化脚本
# cat init_fcgi.sh
#!/bin/bash
#php-fastcgi.php
fcgi_cf="/usr/local/php-fcgi/etc/php.ini"
sed -i '205 s#;open_basedir =#open_basedir = /data/www/wwwroot:/tmp#g' $fcgi_cf
sed -i '210 s#disable_functions =#disable_functions =
phpinfo,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,
dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server#g' $fcgi_cf
sed -i '/expose_php/s/On/Off/' $fcgi_cf
sed -i '/display_errors/s/On/Off/' $fcgi_cf
sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-20060613/"\nextension
= "memcache.so"\n#' $fcgi_cf
6)ZendOptimizer-3.3.3-linux-glibc23-i386 (解压后进入目录./install,安提示选择相关的目录及配置文件存放目录即可)
2.安装Nginx
1)Nginx编译安装
cd pcre-7.7/
./configure
make && make install
cd ../
cd nginx-0.6.31
#vi in_nginx.sh
./configure --user=www --group=www --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-
openssl=/usr/local/openssl
make && make install
sh in_nginx.sh
2)初始化Nginx相关配置
#mkdir /usr/local/nginx/conf/vhosts 创建存放虚拟主机配置文件目录
#cd /usr/local/nginx/conf
#mv nginx.conf nginx.conf_back 将原配置文件备份供以后参考.
#vi nginx.conf 重新创建nginx主配置文件
user www www;
worker_processes 8;
pid /var/run/nginx.pid;
# [ debug | info | notice | warn | error | crit ]
#error_log /var/log/nginx.error_log info;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
#maxclient = worker_processes * worker_connections / cpu_number
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log /data/www/logs/access.log main;
access_log /dev/null;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_intercept_errors on;
gzip on;
gzip_comp_level 4;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_http_version 1.0;
gzip_proxied any;
gzip_types text/plain text/xml text/javascript application/x-javascript text/css text/html application/xml;
#
client_max_body_size 10m;
client_body_buffer_size 256k;
#
#proxy_temp_path /dev/shm/proxy_temp;
fastcgi_temp_path /dev/shm/fastcgi_temp;
client_body_temp_path /dev/shm/client_body_temp;
# The following includes are specified for virtual hosts
include vhosts/bbs.linxutone.org.conf;
include vhosts/down.redocn.com.conf;
include vhosts/count.linuxtone.org.conf;
}
#vi /enable_php5.conf Nginx支持PHP配置文件.
fastcgi_pass 127.0.0.1:8085;
fastcgi_index index.php;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
#fastcgi_param REDIRECT_STATUS 200;
3)配置修改php-fpm脚本
配置php-fpm脚本:
cd /usr/local/php-fcgi/etc/
vi php-fpm.conf 修改如下内容 进入vi编辑器,输入:set nu 显示行号.)
41 <value name="listen_address">127.0.0.1:8085</value>
62 Unix user of processes
63 <value name="user">www</value>
65 Unix group of processes
66 <value name="group">www</value>
79 <value name="max_children">128</value>
80
81 Settings group for 'apache-like' pm style
82 <value name="apache_like">
83
84 Sets the number of server processes created on startup.
85 Used only when 'apache-like' pm_style is selected
86 <value name="StartServers">20</value>
87
88 Sets the desired minimum number of idle server processes.
89 Used only when 'apache-like' pm_style is selected
90 <value name="MinSpareServers">5</value>
91
92 Sets the desired maximum number of idle server processes.
93 Used only when 'apache-like' pm_style is selected
94 <value name="MaxSpareServers">250</value>
104 Set open file desc rlimit
105 <value name="rlimit_files">51200</value>
106
107 Set max core size rlimit
108 <value name="rlimit_core">0</value>
109
110 Chroot to this directory at the start
111 <value name="chroot"></value>
112
113 Chdir to this directory at the start
114 <value name="chdir"></value>
115
116 Redirect workers' stdout and stderr into main error log.
117 If not set, they will be redirected to /dev/null, according to FastCGI specs
118 <value name="catch_workers_output">yes</value>
119
120 How much requests each process should execute before respawn.
121 Useful to work around memory leaks in 3rd party libraries.
122 For endless request processing please specify 0
123 Equivalent to PHP_FCGI_MAX_REQUESTS
124 <value name="max_requests">51200</value>
4) Nginx+PHP(fastcgi)启动脚本参考:http://bbs.linuxtone.org/thread-372-1-2.html |
|