nginx+php5.2.17+memcache+xcache+sign+xcache

 这样的文章很多,我把一次安装PHP模块与大家分享一下,欢迎大牛提出建议。

好了闲话少说,进入正题!


openssl-0.9.8j.tar.gz
memcache-2.2.3.tgz
sign.tgz
xcache-1.2.2.tar.gz
php-5.2.17-fpm-0.5.14.diff.gz
php-5.2.17.tar.bz2
[nginx安装包及依赖包]
pcre-7.7.tar.gz
nginx-1.2.0.tar.gz

 

 

 
一、安装openssl
tar -zxvf openssl-0.9.8j.tar.gz
   cd openssl-0.9.8j
    ls需要的安装包
    ./config --prefix=/usr/local/openssl-0.9.8j
   make && make install
安装完成之后需要测试一下

   /usr/local/openssl-0.9.8j/bin/openssl

二、安装php+fastcgi
1.解压 php-5.2.17.tar.bz2
tar jxvf php-5.2.17.tar.bz2
gzip -cd     php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17
创建一个php扩展模块目录,已便配置编译安装的时候讲这些模块加载到PHP中去
mkdir -p ext
cd ..

  tar -zxvf memcache-2.2.3.tgz
  tar -zxvf xcache-1.2.2.tar.gz
  tar -zxvf sign.tgz
接下来这步很重要(将解压好的这些模块目录移动到上面在PHP创建的扩展目录ext中去)
mv memcache-2.2.3 php-5.2.17/ext/memcache
mv xcache-1.2.2 php-5.2.17/ext/xcache
mv sign php-5.2.17/ext/sign
2.接下来正式安装php
cd php-5.2.17
rm -rf configure #这步删除原来的配置命令 configure(删除的原因的是由于版本的问题,在配置的时候有可能出现问题,我这里是删除,然后用buidconfig从新生成一个configure)

LQDBY-DB64:/data/software/php-5.2.17# ./buildconf --force
出现下面的情况是没有安装 autoconf2.13的问题
Forcing buildconf
buildconf: checking installation...
buildconf: autoconf not found.
           You need autoconf version 2.13 or newer installed
           to build PHP from CVS.
make: *** [buildmk.stamp] Error 1
所以这里需要重新安装 autoconf2.13

 
apt-get install autoconf2.13
export PHP_AUTOCONF=/usr/bin/autoconf2.13
export PHP_AUTOHEADER=/usr/bin/autoheader2.13


 


安装 autoconf2.13之后在执行
./buildconf --force 就没问题了


LQDBY-DB64:/data/software/php-5.2.17# ./configure  --prefix=/usr/local/php-5.2.17 \
> --with-config-file-path=/usr/local/php-5.2.17/etc \
> --with-zlib-dir --enable-sockets --enable-ftp --with-zlib --with-libxml-dir \
> --enable-xml --disable-debug \
> --enable-discard-path --enable-safe-mode \
> --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization \
> --with-curlwrappers --enable-mbregex --enable-fastcgi \
> --enable-fpm --enable-force-cgi-redirect --enable-mbstring \
> --enable-gd-native-ttf --enable-xcache --enable-memcache \
> --enable-sign --with-openssl=/usr/local/openssl-0.9.8j \
> --with-openssl-dir=/usr/local/openssl-0.9.8j
--with-mysql=/usr/local/mysql-5.1.59 如果安装了mysql可以加上这个模块

如果出现这面的对话框说明配置成功
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.


开始编译安装 make -j 8 && make install

修改php-fpm.conf配置文件,并开启fastcgi进程
vim /usr/local/php-5.2.17/etc/php-fpm.conf
讲前面的注释去掉,并修改开启fastcgi进程的用户(也可以不修改)修改完的结果如下

  1 <?xml version="1.0" ?>
  2 <configuration>
  3 
  4         All relative paths in this config are relative to php's install prefix
  5 
  6         <section name="global_options">
  7 
  8                 Pid file
  9                 <value name="pid_file">/usr/local/php-5.2.17/logs/php-fpm.pid</value>
10 
11                 Error log file
12                 <value name="error_log">/usr/local/php-5.2.17/logs/php-fpm.log</value>
13 
14                 Log level
15                 <value name="log_level">notice</value>
16 
17                 When this amount of php processes exited with SIGSEGV or SIGBUS ...
18                 <value name="emergency_restart_threshold">10</value>
19 
20                 ... in a less than this interval of time, a graceful restart will be initiated.
21                 Useful to work around accidental curruptions in accelerator's shared memory.
22                 <value name="emergency_restart_interval">1m</value>
23 
24                 Time limit on waiting child's reaction on signals from master
"/usr/local/php-5.2.17/etc/php-fpm.conf" 156L, 5188C                                           1,1           Top
  1 <?xml version="1.0" ?>
  2 <configuration>
  3 
  4         All relative paths in this config are relative to php's install prefix
  5 
  6         <section name="global_options">
  7 
  8                 Pid file
  9                 <value name="pid_file">/usr/local/php-5.2.17/logs/php-fpm.pid</value>
10 
11                 Error log file
12                 <value name="error_log">/usr/local/php-5.2.17/logs/php-fpm.log</value>
13 
14                 Log level
15                 <value name="log_level">notice</value>
18                 <value name="emergency_restart_threshold">10</value>
19 
20                 ... in a less than this interval of time, a graceful restart will be initiated.
21                 Useful to work around accidental curruptions in accelerator's shared memory.
22                 <value name="emergency_restart_interval">1m</value>
23 
24                 Time limit on waiting child's reaction on signals from master
25                 <value name="process_control_timeout">5s</value>
26 
29 
30         </section>
31 
32         <workers>
33 
34                 <section name="pool">
35 
36                         Name of pool. Used in logs and stats.
37                         <value name="name">default</value>
38 
39                         Address to accept fastcgi requests on.
40                         Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
41                         <value name="listen_address">127.0.0.1:9000</value>
42 
43                         <value name="listen_options">
44 
45                                 Set listen(2) backlog
46                                 <value name="backlog">-1</value>
47 
48                                 Set permissions for unix socket, if one used.
50                                 Many BSD-derrived systems allow connections regardless of permissions.
51                                 <value name="owner"></value>
52                                 <value name="group"></value>
53                                 <value name="mode">0666</value>
54                         </value>
55 
56                         Additional php.ini defines, specific to this pool of workers.
57                         <value name="php_defines">
58                 <!--            <value name="sendmail_path">/usr/sbin/sendmail -t -i</value>            -->
60                         </value>
61 
62                         Unix user of processes
63                         <value name="user">web</value>
64 
65                         Unix group of processes
66                         <value name="group">web</value>
71                                 Sets style of controling worker process count.
72                                 Valid values are 'static' and 'apache-like'
73                                 <value name="style">static</value>
76                                 Equivalent to Apache MaxClients directive.
77                                 Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
78                                 Used with any pm_style.
79                                 <value name="max_children">5</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">35</value>
95 
96                                 </value>
97 
98                         </value>
99 
102                         '0s' means 'off'
103                         <value name="request_terminate_timeout">0s</value>
104 
106                         '0s' means 'off'
107                         <value name="request_slowlog_timeout">0s</value>
108 
109                         The log file for slow requests
110                         <value name="slowlog">logs/slow.log</value>
111 
112                         Set open file desc rlimit
113                         <value name="rlimit_files">1024</value>
114 
115                         Set max core size rlimit
116                         <value name="rlimit_core">0</value>
117 
118                         Chroot to this directory at the start, absolute path
119                         <value name="chroot"></value>
120 
121                         Chdir to this directory at the start, absolute path
122                         <value name="chdir"></value>
123 
124                         Redirect workers' stdout and stderr into main error log.
125                         If not set, they will be redirected to /dev/null, according to FastCGI specs
126                         <value name="catch_workers_output">yes</value>
127 
128                         How much requests each process should execute before respawn.
129                         Useful to work around memory leaks in 3rd party libraries.
130                         For endless request processing please specify 0
131                         Equivalent to PHP_FCGI_MAX_REQUESTS
132                         <value name="max_requests">500</value>
133 
134                         Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
135                         Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
136                         Makes sense only with AF_INET listening socket.
137                         <value name="allowed_clients">127.0.0.1</value>
138 
139                         Pass environment variables like LD_LIBRARY_PATH
140                         All $VARIABLEs are taken from current environment
141                         <value name="environment">
142                                 <value name="HOSTNAME">$HOSTNAME</value>
143                                 <value name="PATH">/usr/local/bin:/usr/bin:/bin</value>
144                                 <value name="TMP">/tmp</value>
145                                 <value name="TMPDIR">/tmp</value>
146                                 <value name="TEMP">/tmp</value>
147                                 <value name="OSTYPE">$OSTYPE</value>
148                                 <value name="MACHTYPE">$MACHTYPE</value>
149                                 <value name="MALLOC_CHECK_">2</value>
150                         </value>
151 
152                 </section>
153 
154         </workers>
155 
156 </configuration>


开启fastcgi进程
/usr/local/php-5.2.17/sbin/php-fpm start
LQDBY-DB64:/data/software/php-5.2.17/ext/mysql# ps -ef |grep php-cgi
root     25745     1  0 16:34 ?        00:00:00 /usr/local/php-5.2.17/bin/php-cgi --fpm --fpm-config /usr/local/php-5.2.17/etc/php-fpm.conf
web      25746 25745  0 16:34 ?        00:00:00 /usr/local/php-5.2.17/bin/php-cgi --fpm --fpm-config /usr/local/php-5.2.17/etc/php-fpm.conf
web      25747 25745  0 16:34 ?        00:00:00 /usr/local/php-5.2.17/bin/php-cgi --fpm --fpm-config /usr/local/php-5.2.17/etc/php-fpm.conf
web      25748 25745  0 16:34 ?        00:00:00 /usr/local/php-5.2.17/bin/php-cgi --fpm --fpm-config /usr/local/php-5.2.17/etc/php-fpm.conf
web      25749 25745  0 16:34 ?        00:00:00 /usr/local/php-5.2.17/bin/php-cgi --fpm --fpm-config /usr/local/php-5.2.17/etc/php-fpm.conf
web      25750 25745  0 16:34 ?        00:00:00 /usr/local/php-5.2.17/bin/php-cgi --fpm --fpm-config /usr/local/php-5.2.17/etc/php-fpm.conf
root     26822 23954  0 17:03 pts/0    00:00:00 grep php-cgi

 


LQDBY-DB64:/data/software/php-5.2.17# netstat -an |grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN

到这里php+fastcgi基本上安装完成了

三、开始安装nginx
1.由于Nginx安装需要pcre的支持所以先安装pcre
tar -zxvf pcre-7.7.tar.gz
cd pcre-7.7
./configure
 make && make install
2.安装nginx程序包
tar -zxvf nginx-1.2.0.tar.gz
cd nginx-1.2.0
./configure --user=web --group=web
--prefix=/usr/local/nginx-1.2.0 
-with-http_stub_status_module
make -j 8 && make isntall

3.开启nginx测试
/usr/local/nginx-1.2.0/sbin/nginx
如果出现下面的错误
/usr/local/nginx-1.2.0/sbin/nginx: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory
解决办法: cp /usr/local/lib/libpcre.so.0 /usr/lib/libpcre.so.0
 
LQDBY-DB64:/data/software/nginx-1.2.0# /usr/local/nginx-1.2.0/sbin/nginx                  
LQDBY-DB64:/data/software/nginx-1.2.0# ps -ef |grep nginx
root      6746     1  0 11:23 ?        00:00:00 nginx: master process /usr/local/nginx-1.2.0/sbin/nginx
web       6747  6746  0 11:23 ?        00:00:00 nginx: worker process           
root      6749 23954  0 11:23 pts/0    00:00:00 grep nginx
 
4.修改nginx配置文件并开启cgi功能
 1 
  2 #user  nobody;
  3 worker_processes  1;
  4 
  5 #error_log  logs/error.log;
  6 #error_log  logs/error.log  notice;
  7 #error_log  logs/error.log  info;
  8 
  9 #pid        logs/nginx.pid;
10 
11 
12 events {
13     worker_connections  1024;
14 }
15 
16 
17 http {
18     include       mime.types;
19     default_type  application/octet-stream;
20 
21     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
22     #                  '$status $body_bytes_sent "$http_referer" '
23     #                  '"$http_user_agent" "$http_x_forwarded_for"';
24 
25     #access_log  logs/access.log  main;
26 
27     sendfile        on;
28     #tcp_nopush     on;
29 
30     #keepalive_timeout  0;
31     keepalive_timeout  65;
32 
33     #gzip  on;
34 
35     server {
36         listen       80;
37         server_name  localhost;
38 
39         #charset koi8-r;
40 
41         #access_log  logs/host.access.log  main;
42 
43         location / {
44             root   html;
45             index  index.html index.htm index.php;
46         }
47 
48         #error_page  404              /404.html;
49 
50         # redirect server error pages to the static page /50x.html
51         #
52         error_page   500 502 503 504  /50x.html;
53         location = /50x.html {
54             root   html;
55         }
56 
57         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
58         #
59         #location ~ \.php$ {
60         #    proxy_pass   http://127.0.0.1;
61         #}
62 
63         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
64         #
65         location ~ \.php$ {
66             root           html;
67             fastcgi_pass   127.0.0.1:9000;
68             fastcgi_index  index.php;
69             fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
70             include        fastcgi.conf;
71         }
72 

73         # deny access to .htaccess files, if Apache's document root
74         # concurs with nginx's one
75         #
76         #location ~ /\.ht {
77         #    deny  all;
78         #}
79     }
80 
81 
82     # another virtual host using mix of IP-, name-, and port-based configuration
83     #
84     #server {
85     #    listen       8000;
86     #    listen       somename:8080;
87     #    server_name  somename  alias  another.alias;
88 
89     #    location / {
90     #        root   html;
91     #        index  index.html index.htm;
92     #    }
93     #}
94 
95 
96     # HTTPS server
97     #
98     #server {
99     #    listen       443;
100     #    server_name  localhost;
101 
102     #    ssl                  on;
103     #    ssl_certificate      cert.pem;
104     #    ssl_certificate_key  cert.key;
105 
106     #    ssl_session_timeout  5m;
107 
108     #    ssl_protocols  SSLv2 SSLv3 TLSv1;
109     #    ssl_ciphers  HIGH:!aNULL:!MD5;
110     #    ssl_prefer_server_ciphers   on;
111 
112     #    location / {
113     #        root   html;
114     #        index  index.html index.htm;
115     #    }
116     #}
117 
118 }

 
5.重启nginx
/usr/local/nginx-1.2.0/sbin/nginx 

6.进行测试
在/usr/local/nginx-1.2.0/html/创建一个index.php网页已便测试
cat /usr/local/nginx-1.2.0/html/index.php
<?php
phpinfo();
?>

 

 


 

你可能感兴趣的:(nginx+php5.2.17+memcache+xcache+sign+xcache)