Skip to content


Nginx 0.7.x + PHP 5.2.10 +Mysql 5.1.37 on CentOs 5.2

系统环境
CentOs 5.2
Linux bora 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009 x86_64 x86_64 x86_64 GNU/Linux

一、升级开源组件
1.利用CentOS Linux系统自带的yum命令安装、升级所需的程序库

  1. sudo -s
  2. LANG=C
  3. yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

2.下载相关软件
A.创建一个下载列表

  1. vi lemp0.7.6_down_list.txt
  1. http://sysoev.ru/nginx/nginx-0.7.61.tar.gz
  2. http://www.php.net/get/php-5.2.10.tar.gz/from/this/mirror
  3. http://php-fpm.org/downloads/php-5.2.10-fpm-0.5.13.diff.gz
  4. http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.37.tar.gz/from/http://mysql.he.net/
  5. http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz
  6. "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"
  7. "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"
  8. http://pecl.php.net/get/memcache-2.2.5.tgz
  9. "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"
  10. ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz
  11. http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
  12. http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
  13. http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
  14. http://pecl.php.net/get/imagick-2.2.2.tgz

B.下载

  1. wget -i lemp0.7.6_down_list.txt

3.安装iconv

  1. tar zxvf libiconv-1.13.tar.gz
  2. cd libiconv-1.13/
  3. ./configure --prefix=/usr/local
  4. make
  5. make install
  6. cd ../

4.安装libmcrypt

  1. tar zxvf libmcrypt-2.5.8.tar.gz
  2. cd libmcrypt-2.5.8/
  3. ./configure
  4. make
  5. make install
  6. /sbin/ldconfig
  7. cd libltdl/
  8. ./configure --enable-ltdl-install
  9. make
  10. make install
  11. cd ../../

5.安装mhash

  1. tar zxvf mhash-0.9.9.9.tar.gz
  2. cd mhash-0.9.9.9/
  3. ./configure
  4. make
  5. make install
  6. cd ../
  7.  
  8. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
  9. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
  10. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
  11. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
  12. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
  13. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
  14. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
  15. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
  16. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

6.安装mcrypt

  1. tar zxvf mcrypt-2.6.8.tar.gz
  2. cd mcrypt-2.6.8/
  3. /sbin/ldconfig
  4. ./configure
  5. make
  6. make install
  7. cd ../

错误

  1. checking for libmcrypt - version >= 2.5.0...
  2. *** 'libmcrypt-config --version' returned 2.4.0, but LIBMCRYPT (2.5.8)
  3. *** was found! If libmcrypt-config was correct, then it is best
  4. *** to remove the old version of LIBMCRYPT. You may also be able to fix the error
  5. *** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing
  6. *** /etc/ld.so.conf. Make sure you have run ldconfig if that is
  7. *** required on your system.
  8. *** If libmcrypt-config was wrong, set the environment variable LIBMCRYPT_CONFIG
  9. *** to point to the correct copy of libmcrypt-config, and remove the file config.cache
  10. *** before re-running configure
  11. configure: error: *** libmcrypt was not found

解决方法

  1. ln -s   /usr/local/bin/libmcrypt-config   /usr/bin/libmcrypt-config

二、安装mysql
1.添加用户及用户组

  1. /usr/sbin/groupadd mysql
  2. /usr/sbin/useradd -g mysql mysql -d /dev/null -s /sbin/nologin

2.编译mysql

  1. tar zxvf mysql-5.1.37.tar.gz
  2. cd mysql-5.1.37/
  3.  
  4. CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/opt/mysql --localstatedir=/opt/mysql/var --sysconfdir=/opt/mysql --with-unix-socket-path=/opt/mysql/mysql.sock --with-charset=gbk --with-collation=gbk_chinese_ci --with-extra-charsets=gbk,gb2312,utf8 --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-debug --with-big-tables --with-readline --with-ssl --with-pthread --enable-thread-safe-client --with-embedded-server --enable-local-infile --with-plugins=innobase
  5. make
  6. make install

3.copy配置文件

  1. #512M内存和web共用
  2. cp support-files/my-medium.cnf /opt/mysql/my.cnf
  3. #2G内存和web共用
  4. #cp support-files/my-large.cnf /opt/mysql/my.cnf
  5. #删除默认的my.cnf
  6. rm /etc/my.cnf

4.初始数据库

  1. /opt/mysql/bin/mysql_install_db --defaults-file=/opt/mysql/my.cnf --basedir=/opt/mysql --datadir=/opt/mysql/var --user=mysql --pid-file=/opt/mysql/var/mysql.pid --skip-locking --socket=/opt/mysql/mysql.sock

5.设置文件夹属主

  1. chmod +w /opt/mysql
  2. chown -R mysql:mysql /opt/mysql
  3.  
  4. cd ..
  5. chgrp website /opt/mysql/my.cnf
  6. chmod 0664 /opt/mysql/my.cnf

6.启动文件及自动启动

  1. cp support-files/mysql.server /opt/mysql/bin/
  2. chmod 755 /opt/mysql/bin/mysql.server
  3.  
  4. #A.自动启动
  5. cp support-files/mysql.server /etc/init.d/mysql
  6. chmod 755 /etc/init.d/mysql
  7. chkconfig --add mysql
  8. #某些linux上
  9. #chkconfig --level 345 mysql on
  10. #开启服务
  11. /etc/init.d/mysql start
  12. #关闭服务
  13. #/etc/init.d/mysql stop 
  14.  
  15. #B.脚本启动
  16. #我这里使用lemp脚本启动。
  17. #lemp脚本见下方

7.修改mysql root密码

  1. #123456为密码
  2. /opt/mysql/bin/mysqladmin -uroot  password 123456
  3. #测试密码
  4. /opt/mysql/bin/mysql -uroot -p
  5. Enter password:

8.编辑my.cnf

  1. vi /opt/mysql/my.cnf

关闭log_bin
将log-bin=mysql-bin注释掉,需要热备份或主从服务器的可以保留,开启后会占很多空间
开启innodb
将innodb开头的注释去掉,除了innodb_log_arch_dir参数,开启它将无法启动msyql
修改完成后重启mysql服务

三、安装php
1.编译php

  1. tar zxvf php-5.2.10.tar.gz
  2. gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1
  3. cd php-5.2.10/
  4. ./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-mysql=/opt/mysql --with-mysqli=/opt/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap  --enable-xml --enable-zend-multibyte --disable-debug --disable-ipv6 --without-pear
  5. make ZEND_EXTRA_LIBS='-liconv'
  6. make install
  7. cp php.ini-dist /opt/php/etc/php.ini

这个版本的php有个bug,带上pear时会出错

  1. Fatal error: Error: cannot open phar "/home/andychu/lemp/php-5.2.10/pear/install-pear-nozlib.phar" in /home/andychu/lemp/php-5.2.10/pear/install-pear-nozlib.phar on line 795

2.手动安装pear

  1. cd /opt/php/
  2. curl http://pear.php.net/go-pear |  /opt/php/bin/php

3.安装memcache

  1. tar zxvf memcache-2.2.5.tgz
  2. cd memcache-2.2.5/
  3. /opt/php/bin/phpize
  4. ./configure --with-php-config=/opt/php/bin/php-config
  5. make
  6. make install
  7. cd ..

4.安装eaccelerator

  1. tar jxvf eaccelerator-0.9.5.3.tar.bz2
  2. cd eaccelerator-0.9.5.3/
  3. /opt/php/bin/phpize
  4. ./configure  --enable-eaccelerator=shared --with-php-config=/opt/php/bin/php-config
  5. make
  6. make install
  7. cd ..

5.安装PDO_MYSQL

  1. tar zxvf PDO_MYSQL-1.0.2.tgz
  2. cd PDO_MYSQL-1.0.2/
  3. /opt/php/bin/phpize
  4. ./configure --with-php-config=/opt/php/bin/php-config --with-pdo-mysql=/opt/mysql
  5. make
  6. make install
  7. cd ../

6.安装ImageMagick

  1. tar zxvf ImageMagick.tar.gz
  2. cd ImageMagick-6.5.1-2/
  3. ./configure
  4. make
  5. make install
  6. cd ../

7.安装imagick

  1. tar zxvf imagick-2.2.2.tgz
  2. cd imagick-2.2.2/
  3. /opt/php/bin/phpize
  4. ./configure --with-php-config=/opt/php/bin/php-config
  5. make
  6. make install
  7. cd ../

8.编辑php.ini

  1. mkdir -p /opt/php/eaccelerator_cache
  2. vi /opt/php/etc/php.ini

  手工修改:查找/opt/php/etc/php.ini中的extension_dir = "./"
  修改为extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20060613/"
  并在此行后增加以下几行,然后保存:
  extension = "memcache.so"
  extension = "pdo_mysql.so"
  extension = "imagick.so"

  再查找output_buffering = Off
  修改为output_buffering = On

9.配置eAccelerator加速PHP
按shift+g键跳到配置文件的最末尾,加上以下配置信息:

  1. [eaccelerator]
  2. zend_extension="/opt/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
  3. eaccelerator.shm_size="64"
  4. eaccelerator.cache_dir="/opt/php/eaccelerator_cache"
  5. eaccelerator.enable="1"
  6. eaccelerator.optimizer="1"
  7. eaccelerator.check_mtime="1"
  8. eaccelerator.debug="0"
  9. eaccelerator.filter=""
  10. eaccelerator.shm_max="0"
  11. eaccelerator.shm_ttl="3600"
  12. eaccelerator.shm_prune_period="3600"
  13. eaccelerator.shm_only="0"
  14. eaccelerator.compress="1"
  15. eaccelerator.compress_level="9"

10.创建web用户

  1. /usr/sbin/groupadd website
  2. /usr/sbin/groupadd www -g 48
  3. /usr/sbin/useradd -g website www -d /dev/null -s /sbin/nologin
  4. mkdir -p /opt/htdocs/www/nginx
  5. chmod -R 0775 /opt/htdocs/
  6. chown -R www:website /opt/htdocs/

11.创建php-fpm配置文件
(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
在/opt/php/etc/目录中创建php-fpm.conf文件:

  1. rm -f /opt/php/etc/php-fpm.conf
  2. vi /opt/php/etc/php-fpm.conf

和原始配置文件的差别

  1. 用户组->www
  2. max_children=64
  3. MaxApareServers=250
  4. rlimit_files=51200
  5. max_requests=51200
  6. 去掉注释

12.优化文件句柄并开启php

  1. ulimit -SHn 51200
  2. /opt/php/sbin/php-fpm start

#/opt/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。

四、安装nginx
1.pcre

  1. tar zxvf pcre-7.9.tar.gz
  2. cd pcre-7.9/
  3. ./configure --enable-utf8 --enable-unicode-properties
  4. make && make install
  5. cd ../

2.nginx

  1. tar zxvf nginx-0.7.61.tar.gz
  2. cd nginx-0.7.61/

A关闭debug模式来减少nginx大小
http://bianbian.org/technology/271.html

  1. du /opt/nginx/sbin/nginx
  2. #未做优化时的大小
  3. 1712    /opt/nginx/sbin/nginx
  4. #优化后的大小
  5. 404     /opt/nginx/sbin/nginx
  6. vi auto/cc/gcc
  7.     # 最后几行sheft+g
  8.     #注释这行
  9.     #CFLAGS=”$CFLAGS -g”

B伪装header

  1. vi src/core/nginx.h
  2.    #define NGINX_VERSION      "1.0"
  3.    #define NGINX_VER          "C1GWS/" NGINX_VERSION

C编译

  1. ./configure --user=www --group=website --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module
  2. make
  3. make install
  4. cd ../

3.修改权限

  1. chown -R www:website /opt/nginx/logs/
  2. chmod -R 0775 /opt/nginx/logs/
  3. chown -R www:website /opt/nginx/conf/
  4. chmod -R 0775 /opt/nginx/conf/

4.创建Nginx配置文件

  1. rm -f /opt/nginx/conf/nginx.conf
  2. vi /opt/nginx/conf/nginx.conf

示例为discuz7的配置

  1. user  www website;
  2.  
  3. worker_processes 8;
  4.  
  5. error_log  /var/log/nginx/nginx_error.log  crit;
  6.  
  7. pid        /dev/shm/nginx.pid;
  8.  
  9. #Specifies the value for maximum file descriptors that can be opened by this process.
  10. worker_rlimit_nofile 51200;
  11.  
  12. events
  13. {
  14.      use epoll;
  15.  
  16.      worker_connections 51200;
  17. }
  18.  
  19. http
  20. {
  21.      include       mime.types;
  22.      default_type  application/octet-stream;
  23.  
  24.      log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
  25.    '$status $body_bytes_sent "$http_referer" '
  26.    '"$http_user_agent" $http_x_forwarded_for';
  27.  
  28.  
  29.      server_names_hash_bucket_size 128;
  30.      client_header_buffer_size 32k;
  31.      large_client_header_buffers 4 32k;
  32.      client_body_timeout 60;
  33.      client_max_body_size 8m;
  34.  
  35.      #linux 2.4+
  36.      sendfile on;
  37.      tcp_nopush     on;
  38.      tcp_nodelay on;
  39.  
  40.      server_name_in_redirect off;
  41.  
  42.      keepalive_timeout 60;
  43.  
  44.      fastcgi_intercept_errors on;
  45.      fastcgi_hide_header X-Powered-By;
  46.      fastcgi_connect_timeout 180;
  47.      fastcgi_send_timeout 180;
  48.      fastcgi_read_timeout 180;
  49.      fastcgi_buffer_size 128k;
  50.      fastcgi_buffers 4 128K;
  51.      fastcgi_busy_buffers_size 128k;
  52.      fastcgi_temp_file_write_size 128k;
  53.      fastcgi_temp_path /dev/shm;
  54.  
  55.      gzip on;
  56.      gzip_min_length  1k;
  57.      gzip_comp_level 5;
  58.      gzip_buffers     4 16k;
  59.      gzip_http_version 1.1;
  60.      gzip_types       text/plain application/x-javascript text/css application/xml;
  61.  
  62.      limit_zone   one  $binary_remote_addr  10m;
  63.  
  64.      server
  65.      {
  66.              listen       80;
  67.              server_name  bbs.c1gstudio.com;
  68.              index index.html index.htm index.php;
  69.              root  /opt/htdocs/www;
  70.      error_page 404 403 /404.html;
  71.         
  72.      location ~/\.ht {
  73.          deny all;
  74.      }
  75.  
  76.      location ~ /bbs/attachment\.php?$ {
  77.                   include fcgi.conf;     
  78.                   fastcgi_pass  127.0.0.1:9000;
  79.                   fastcgi_index index.php;
  80.                  limit_conn   one  1;
  81.                  limit_rate 30k;
  82.      }
  83.  
  84.              location ~ .*\.php?$
  85.              {
  86.                   #fastcgi_pass  unix:/tmp/php-cgi.sock;
  87.                   fastcgi_pass  127.0.0.1:9000;
  88.                   fastcgi_index index.php;
  89.                   include fcgi.conf;     
  90.              }
  91.  
  92. rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last;
  93. rewrite ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 last;
  94. rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3 last;
  95. rewrite ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 last;
  96. rewrite ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 last;
  97.  
  98.        location ~(favicon.ico) {
  99.                  log_not_found off;
  100. expires 99d;
  101. break;
  102.      }
  103.      location ~(robots.txt) {
  104.                  log_not_found off;
  105. expires 7d;
  106. break;
  107.      }
  108.  
  109.      location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {
  110. valid_referers none blocked *.c1gstudio.com;
  111. if ($invalid_referer) {
  112.     rewrite ^/ http://leech.c1gstudio.com/leech_bbs.gif;
  113.     return 412;
  114. }
  115.                  access_log   off;
  116.                  root /opt/htdocs/www;
  117. expires 7d;
  118. break;
  119.      }
  120.  
  121.              access_log  /var/log/nginx/bbs.c1gstudio.com.log  access;
  122.      }
  123.  
  124. }

5.在/opt/nginx/conf/目录中创建fcgi.conf文件

  1. vi /opt/nginx/conf/fcgi.conf
  1. fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
  2. fastcgi_param  SERVER_SOFTWARE    nginx;
  3.  
  4. fastcgi_param  QUERY_STRING       $query_string;
  5. fastcgi_param  REQUEST_METHOD     $request_method;
  6. fastcgi_param  CONTENT_TYPE       $content_type;
  7. fastcgi_param  CONTENT_LENGTH     $content_length;
  8.  
  9. fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
  10. fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
  11. fastcgi_param  REQUEST_URI        $request_uri;
  12. fastcgi_param  DOCUMENT_URI       $document_uri;
  13. fastcgi_param  DOCUMENT_ROOT      $document_root;
  14. fastcgi_param  SERVER_PROTOCOL    $server_protocol;
  15.  
  16. fastcgi_param  REMOTE_ADDR        $remote_addr;
  17. fastcgi_param  REMOTE_PORT        $remote_port;
  18. fastcgi_param  SERVER_ADDR        $server_addr;
  19. fastcgi_param  SERVER_PORT        $server_port;
  20. fastcgi_param  SERVER_NAME        $server_name;
  21.  
  22. # PHP only, required if PHP was built with --enable-force-cgi-redirect
  23. fastcgi_param  REDIRECT_STATUS    200;

6.nginx的日志滚动

  1. mkdir 0775 /opt/shell
  2. chgrp website /opt/shell
  3. vi /opt/shell/nginx_log.sh
  1. #!/bin/sh
  2. log_dir=/var/log/nginx/logs
  3. yesterday=`date +%Y%m%d`
  4. lastday=`date +%Y%m%d -d '-1 month'`
  5. /bin/rm ${log_dir}/access.${lastday}.log
  6. /bin/rm ${log_dir}/nginx_error.${lastday}.log
  7. /bin/mv ${log_dir}/access.log ${log_dir}/access.${yesterday}.log
  8. /bin/mv ${log_dir}/nginx_error.log ${log_dir}/nginx_error.${yesterday}.log
  9. kill -USR1 `cat /opt/nginx/nginx.pid`
  10. /bin/gzip ${log_dir}/access.${yesterday}.log &
  11. /bin/gzip ${log_dir}/nginx_error.${yesterday}.log &

7.在crontab里每日23:59时

  1. 59 23 * * * /bin/sh /opt/shell/nginx_log.sh > /dev/null 2>&1

8.启动nginx和php

  1. /opt/php/sbin/php-fpm start
  2. /opt/php/nginx/sbin/nginx

五、优化Linux参数
1.优化Linux内核参数

  1. vi /etc/sysctl.conf
  1. # Add
  2. net.ipv4.tcp_max_syn_backlog = 65536
  3. net.core.netdev_max_backlog =  32768
  4. net.core.somaxconn = 32768
  5.  
  6. net.core.wmem_default = 8388608
  7. net.core.rmem_default = 8388608
  8. net.core.rmem_max = 16777216
  9. net.core.wmem_max = 16777216
  10.  
  11. net.ipv4.tcp_timestamps = 0
  12. net.ipv4.tcp_synack_retries = 2
  13. net.ipv4.tcp_syn_retries = 2
  14.  
  15. net.ipv4.tcp_tw_recycle = 1
  16. #net.ipv4.tcp_tw_len = 1
  17. net.ipv4.tcp_tw_reuse = 1
  18.  
  19. net.ipv4.tcp_mem = 94500000 915000000 927000000
  20. net.ipv4.tcp_max_orphans = 3276800
  21.  
  22. #net.ipv4.tcp_fin_timeout = 30
  23. #net.ipv4.tcp_keepalive_time = 120
  24. net.ipv4.ip_local_port_range = 1024  65535

2.优化文件句柄

  1. vi /etc/security/limits.conf

文件尾部增加

  1. * soft nofile 51200
  2. * hard nofile 51200

设置为星号代表全局
这个当中的硬限制是实际的限制,而软限制,是warnning限制,只会做出warning。

重启软件
退出控制台后就生效

使配置立即生效:

  1. /sbin/sysctl -p

六、自动启动nginx+php+mysql

  1. vi /etc/rc.local

在末尾添加

  1. ulimit -SHn 51200
  2. /opt/lemp start

点此下载lemp 脚本

参考:
nginx+php(FCGI)+xcache+mysql on as4
http://blog.c1gstudio.com/archives/152

Nginx 0.7.x + PHP 5.2.10(FastCGI)搭建胜过Apache十倍的Web服务器
http://blog.s135.com/nginx_php_v5

===================
2009/11/2 更新
内核增加参数
net.ipv4.ip_conntrack_max = 262144 #8G内存64位配制
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 36000
参考:
http://www.wallfire.org/misc/netfilter_conntrack_perf.txt

===================
2010-3-24更新
安装Zend Optimizer
discuz中电子商备功能加密了代码需用此模块
安装Zend Optimizer最为简单,到Zend官方网站下载相应CPU的版本
http://www.zend.com/en/products/guard/downloads
文件夹下有个data目录,然后根据自己的php的版本选择合适的ZendOptimizer.so
然后把这个so加载到php.ini中。

  1. tar zxvf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
  2. cd ZendOptimizer-3.3.9-linux-glibc23-x86_64
  3. cp data/5_2_x_comp/ZendOptimizer.so /opt/php/lib/php/extensions/no-debug-non-zts-20060613/

编辑配置文件php.ini加入

  1. extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20060613/"
  2. extension = "ZendOptimizer.so"
  1. /opt/php-5.2.10/sbin/php-fpm: line 40: 28411 Segmentation fault      $php_fpm_BIN --fpm $php_opts

tail /var/log/messages

  1. Mar 25 10:12:50 c1g kernel: php-cgi[30784]: segfault at 00002b9ea63cdc60 rip 00002b9ea63cdc60 rsp 00007fff08c47cd0 error 14

注意如果同时使用eaccelerator,不要使用上面的方式,需将zend optimize放在eaccelerator的下面,让eaccelerator先启动
否则phpfpm的reload会失败,启动时也会报错.

  1. [eaccelerator]
  2. zend_extension="/opt/php-5.2.10/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
  3. eaccelerator.shm_size="64"
  4. eaccelerator.cache_dir="/opt/php-5.2.10/eaccelerator_cache"
  5. eaccelerator.enable="1"
  6. eaccelerator.optimizer="1"
  7. eaccelerator.check_mtime="1"
  8. eaccelerator.debug="0"
  9. eaccelerator.filter=""
  10. eaccelerator.shm_max="0"
  11. eaccelerator.shm_ttl="3600"
  12. eaccelerator.shm_prune_period="3600"
  13. eaccelerator.shm_only="0"
  14. eaccelerator.compress="1"
  15. eaccelerator.compress_level="9"
  16.  
  17. [Zend]
  18. zend_extension="/opt/php-5.2.10/lib/php/extensions/no-debug-non-zts-20060613/ZendOptimizer.so"
  19. zend_optimizer.enable_loader = 1
  20. zend_optimizer.optimization_level=15
  21. zend_optimizer.disable_licensing=0

/opt/php-5.2.10/bin/php -v

  1. Copyright (c) 1997-2009 The PHP Group
  2. Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
  3.     with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
  4.     with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

重启php后在phpinfo中可以看到
with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

参考
http://genko.580sw.com/index.php/2010/01/06/linux%e4%b8%8bzend%e4%b8%8e-eaccelerator%e5%85%b1%e5%ad%98/

收藏与分享

Posted in Nginx, 技术.

Tagged with , , , , .


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Continuing the Discussion

  1. | 况恒 –每天做早操 linked to this post on 九月 25, 2009

    [...] 参考地址:http://blog.c1gstudio.com/archives/818 [...]



Some HTML is OK

or, reply to this post via trackback.