1. mkdir -p /data0/software
  2. cd /data0/software
  3. wget http://sysoev.ru/nginx/nginx-0.8.46.tar.gz
  4. wget http://www.php.net/get/php-5.2.14.tar.gz/from/this/mirror
  5. wget http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz
  6. wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.3-m3.tar.gz/from/http://mysql.he.net/
  7. wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
  8. wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"
  9. wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"
  10. wget http://pecl.php.net/get/memcache-2.2.5.tgz
  11. wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"
  12. wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
  13. wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
  14. wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
  15. wget http://blog.zyan.cc/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
  16. wget http://pecl.php.net/get/imagick-2.3.0.tgz
  1. mkdir -p /data0/software
  2. cd /data0/software
  3. wget http://blog.zyan.cc/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz
  4. wget http://blog.zyan.cc/soft/linux/nginx_php/php/php-5.2.14.tar.gz
  5. wget http://blog.zyan.cc/soft/linux/nginx_php/phpfpm/php-5.2.14-fpm-0.5.14.diff.gz
  6. wget http://blog.zyan.cc/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
  7. wget http://blog.zyan.cc/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
  8. wget http://blog.zyan.cc/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
  9. wget http://blog.zyan.cc/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
  10. wget http://blog.zyan.cc/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
  11. wget http://blog.zyan.cc/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
  12. wget http://blog.zyan.cc/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
  13. wget http://blog.zyan.cc/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
  14. wget http://blog.zyan.cc/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
  15. wget http://blog.zyan.cc/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
  16. wget http://blog.zyan.cc/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz
  1. 二、安装PHP 5.2.(FastCGI模式)
  2.   、编译安装PHP 5.2.14所需的支持库:
  3. tar zxvf libiconv-1.13..tar.gz
  4. cd libiconv-1.13./
  5. ./configure --prefix=/usr/local
  6. make
  7. make install
  8. cd ../
  9.  
  10. tar zxvf libmcrypt-2.5..tar.gz
  11. cd libmcrypt-2.5./
  12. ./configure
  13. make
  14. make install
  15. /sbin/ldconfig
  16. cd libltdl/
  17. ./configure --enable-ltdl-install
  18. make
  19. make install
  20. cd ../../
  21.  
  22. tar zxvf mhash-0.9.9.9.tar.gz
  23. cd mhash-0.9.9.9/
  24. ./configure
  25. make
  26. make install
  27. cd ../
  28.  
  29. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
  30. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
  31. ln -s /usr/local/lib/libmcrypt.so. /usr/lib/libmcrypt.so.
  32. ln -s /usr/local/lib/libmcrypt.so.4.4. /usr/lib/libmcrypt.so.4.4.
  33. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
  34. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
  35. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
  36. ln -s /usr/local/lib/libmhash.so. /usr/lib/libmhash.so.
  37. ln -s /usr/local/lib/libmhash.so.2.0. /usr/lib/libmhash.so.2.0.
  38. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
  39.  
  40. tar zxvf mcrypt-2.6..tar.gz
  41. cd mcrypt-2.6./
  42. /sbin/ldconfig
  43. ./configure
  44. make
  45. make install
  46. cd ../
  47.  
  48.   、编译安装MySQL 5.5.-m3
  49. /usr/sbin/groupadd mysql
  50. /usr/sbin/useradd -g mysql mysql
  51. tar zxvf mysql-5.5.-m3.tar.gz
  52. cd mysql-5.5.-m3/
  53. ./configure --prefix=/usr/local/webserver/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg
  54. make && make install
  55. chmod +w /usr/local/webserver/mysql
  56. chown -R mysql:mysql /usr/local/webserver/mysql
  57. cd ../
  58.  
  59.   附:以下为附加步骤,如果你想在这台服务器上运行MySQL数据库,则执行以下几步。如果你只是希望让PHP支持MySQL扩展库,能够连接其他服务器上的MySQL数据库,那么,以下两步无需执行。
  60.  
  61.   ①、创建MySQL数据库存放目录
  62. mkdir -p /data0/mysql//data/
  63. mkdir -p /data0/mysql//binlog/
  64. mkdir -p /data0/mysql//relaylog/
  65. chown -R mysql:mysql /data0/mysql/
  66.  
  67.   ②、以mysql用户帐号的身份建立数据表:
  68. /usr/local/webserver/mysql/bin/mysql_install_db --basedir=/usr/local/webserver/mysql --datadir=/data0/mysql//data --user=mysql
  69.  
  70.   ③、创建my.cnf配置文件:
  71. vi /data0/mysql//my.cnf
  72.  
  73.   输入以下内容:
  74. 引用
  75. [client]
  76. character-set-server = utf8
  77. port =
  78. socket = /tmp/mysql.sock
  79.  
  80. [mysqld]
  81. character-set-server = utf8
  82. replicate-ignore-db = mysql
  83. replicate-ignore-db = test
  84. replicate-ignore-db = information_schema
  85. user = mysql
  86. port =
  87. socket = /tmp/mysql.sock
  88. basedir = /usr/local/webserver/mysql
  89. datadir = /data0/mysql//data
  90. log-error = /data0/mysql//mysql_error.log
  91. pid-file = /data0/mysql//mysql.pid
  92. open_files_limit =
  93. back_log =
  94. max_connections =
  95. max_connect_errors =
  96. table_cache =
  97. external-locking = FALSE
  98. max_allowed_packet = 32M
  99. sort_buffer_size = 1M
  100. join_buffer_size = 1M
  101. thread_cache_size =
  102. #thread_concurrency =
  103. query_cache_size = 512M
  104. query_cache_limit = 2M
  105. query_cache_min_res_unit = 2k
  106. default-storage-engine = MyISAM
  107. thread_stack = 192K
  108. transaction_isolation = READ-COMMITTED
  109. tmp_table_size = 246M
  110. max_heap_table_size = 246M
  111. long_query_time =
  112. log-slave-updates
  113. log-bin = /data0/mysql//binlog/binlog
  114. binlog_cache_size = 4M
  115. binlog_format = MIXED
  116. max_binlog_cache_size = 8M
  117. max_binlog_size = 1G
  118. relay-log-index = /data0/mysql//relaylog/relaylog
  119. relay-log-info-file = /data0/mysql//relaylog/relaylog
  120. relay-log = /data0/mysql//relaylog/relaylog
  121. expire_logs_days =
  122. key_buffer_size = 256M
  123. read_buffer_size = 1M
  124. read_rnd_buffer_size = 16M
  125. bulk_insert_buffer_size = 64M
  126. myisam_sort_buffer_size = 128M
  127. myisam_max_sort_file_size = 10G
  128. myisam_repair_threads =
  129. myisam_recover
  130.  
  131. interactive_timeout =
  132. wait_timeout =
  133.  
  134. skip-name-resolve
  135. #master-connect-retry =
  136. slave-skip-errors = ,,,,,,
  137.  
  138. #master-host = 192.168.1.2
  139. #master-user = username
  140. #master-password = password
  141. #master-port =
  142.  
  143. server-id =
  144.  
  145. innodb_additional_mem_pool_size = 16M
  146. innodb_buffer_pool_size = 512M
  147. innodb_data_file_path = ibdata1:256M:autoextend
  148. innodb_file_io_threads =
  149. innodb_thread_concurrency =
  150. innodb_flush_log_at_trx_commit =
  151. innodb_log_buffer_size = 16M
  152. innodb_log_file_size = 128M
  153. innodb_log_files_in_group =
  154. innodb_max_dirty_pages_pct =
  155. innodb_lock_wait_timeout =
  156. innodb_file_per_table =
  157.  
  158. #log-slow-queries = /data0/mysql//slow.log
  159. #long_query_time =
  160.  
  161. [mysqldump]
  162. quick
  163. max_allowed_packet = 32M
  164.  
  165.   ④、创建管理MySQL数据库的shell脚本:
  166. vi /data0/mysql//mysql
  167.  
  168.   输入以下内容(这里的用户名admin和密码12345678接下来的步骤会创建):
  169. #!/bin/sh
  170.  
  171. mysql_port=
  172. mysql_username="admin"
  173. mysql_password=""
  174.  
  175. function_start_mysql()
  176. {
  177. printf "Starting MySQL...\n"
  178. /bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/data0/mysql/${mysql_port}/my.cnf >& > /dev/null &
  179. }
  180.  
  181. function_stop_mysql()
  182. {
  183. printf "Stoping MySQL...\n"
  184. /usr/local/webserver/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown
  185. }
  186.  
  187. function_restart_mysql()
  188. {
  189. printf "Restarting MySQL...\n"
  190. function_stop_mysql
  191. sleep
  192. function_start_mysql
  193. }
  194.  
  195. function_kill_mysql()
  196. {
  197. kill - $(ps -ef &#; grep 'bin/mysqld_safe' &#; grep ${mysql_port} &#; awk '{printf $2}')
  198. kill - $(ps -ef &#; grep 'libexec/mysqld' &#; grep ${mysql_port} &#; awk '{printf $2}')
  199. }
  200.  
  201. if [ "$1" = "start" ]; then
  202. function_start_mysql
  203. elif [ "$1" = "stop" ]; then
  204. function_stop_mysql
  205. elif [ "$1" = "restart" ]; then
  206. function_restart_mysql
  207. elif [ "$1" = "kill" ]; then
  208. function_kill_mysql
  209. else
  210. printf "Usage: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill}\n"
  211. fi
  212.  
  213.   ⑤、赋予shell脚本可执行权限:
  214. chmod +x /data0/mysql//mysql
  215.  
  216.   ⑥、启动MySQL
  217. /data0/mysql//mysql start
  218.  
  219.   ⑦、通过命令行登录管理MySQL服务器(提示输入密码时直接回车):
  220. /usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
  221.  
  222.   ⑧、输入以下SQL语句,创建一个具有root权限的用户(admin)和密码():
  223. GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '';
  224. GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '';
  225.  
  226.   ⑨、(可选)停止MySQL
  227. /data0/mysql//mysql stop
  228.  
  229.   、编译安装PHPFastCGI模式)
  230. tar zxvf php-5.2..tar.gz
  231. gzip -cd php-5.2.-fpm-0.5..diff.gz | patch -d php-5.2. -p1
  232. cd php-5.2./
  233. ./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --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-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
  234. make ZEND_EXTRA_LIBS='-liconv'
  235. make install
  236. cp php.ini-dist /usr/local/webserver/php/etc/php.ini
  237. cd ../
  238.  
  239.   、编译安装PHP5扩展模块
  240. tar zxvf memcache-2.2..tgz
  241. cd memcache-2.2./
  242. /usr/local/webserver/php/bin/phpize
  243. ./configure --with-php-config=/usr/local/webserver/php/bin/php-config
  244. make
  245. make install
  246. cd ../
  247.  
  248. tar jxvf eaccelerator-0.9.6.1.tar.bz2
  249. cd eaccelerator-0.9.6.1/
  250. /usr/local/webserver/php/bin/phpize
  251. ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
  252. make
  253. make install
  254. cd ../
  255.  
  256. tar zxvf PDO_MYSQL-1.0..tgz
  257. cd PDO_MYSQL-1.0./
  258. /usr/local/webserver/php/bin/phpize
  259. ./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-mysql=/usr/local/webserver/mysql
  260. make
  261. make install
  262. cd ../
  263.  
  264. tar zxvf ImageMagick.tar.gz
  265. cd ImageMagick-6.5.-/
  266. ./configure
  267. make
  268. make install
  269. cd ../
  270.  
  271. tar zxvf imagick-2.3..tgz
  272. cd imagick-2.3./
  273. /usr/local/webserver/php/bin/phpize
  274. ./configure --with-php-config=/usr/local/webserver/php/bin/php-config
  275. make
  276. make install
  277. cd ../
  278.  
  279.   、修改php.ini文件
  280.   手工修改:查找/usr/local/webserver/php/etc/php.ini中的extension_dir = "./"
  281.   修改为extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
  282.   并在此行后增加以下几行,然后保存:
  283.   extension = "memcache.so"
  284.   extension = "pdo_mysql.so"
  285.   extension = "imagick.so"
  286.  
  287.   再查找output_buffering = Off
  288.   修改为output_buffering = On
  289.  
  290.   再查找; cgi.fix_pathinfo=
  291.   修改为cgi.fix_pathinfo=,防止Nginx文件类型错误解析漏洞。
  292.  
  293.   自动修改:若嫌手工修改麻烦,可执行以下shell命令,自动完成对php.ini文件的修改:
  294. sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\nextension = "imagick.so"\n#' /usr/local/webserver/php/etc/php.ini
  295. sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/webserver/php/etc/php.ini
  296. sed -i "s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g" /usr/local/webserver/php/etc/php.ini
  297. sed -i "s#; cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g" /usr/local/webserver/php/etc/php.ini
  298.  
  299.   、配置eAccelerator加速PHP
  300. mkdir -p /usr/local/webserver/eaccelerator_cache
  301. vi /usr/local/webserver/php/etc/php.ini
  302.  
  303.   shift+g键跳到配置文件的最末尾,加上以下配置信息:
  304. 引用
  305. [eaccelerator]
  306. zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
  307. eaccelerator.shm_size=""
  308. eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
  309. eaccelerator.enable=""
  310. eaccelerator.optimizer=""
  311. eaccelerator.check_mtime=""
  312. eaccelerator.debug=""
  313. eaccelerator.filter=""
  314. eaccelerator.shm_max=""
  315. eaccelerator.shm_ttl=""
  316. eaccelerator.shm_prune_period=""
  317. eaccelerator.shm_only=""
  318. eaccelerator.compress=""
  319. eaccelerator.compress_level=""
  320.  
  321.   、创建www用户和组,以及供blog.zyan.ccwww.zyan.cc两个虚拟主机使用的目录:
  322. /usr/sbin/groupadd www
  323. /usr/sbin/useradd -g www www
  324. mkdir -p /data0/htdocs/blog
  325. chmod +w /data0/htdocs/blog
  326. chown -R www:www /data0/htdocs/blog
  327. mkdir -p /data0/htdocs/www
  328. chmod +w /data0/htdocs/www
  329. chown -R www:www /data0/htdocs/www
  330.  
  331.   、创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
  332.   在/usr/local/webserver/php/etc/目录中创建php-fpm.conf文件:
  333. rm -f /usr/local/webserver/php/etc/php-fpm.conf
  334. vi /usr/local/webserver/php/etc/php-fpm.conf
  335.  
  336.   输入以下内容(如果您安装 Nginx + PHP 用于程序调试,请将以下的<value name="display_errors"></value>改为<value name="display_errors"></value>,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页):
  337. <?xml version="1.0" ?>
  338. <configuration>
  339.  
  340. All relative paths in this config are relative to php's install prefix
  341.  
  342. <section name="global_options">
  343.  
  344. Pid file
  345. <value name="pid_file">/usr/local/webserver/php/logs/php-fpm.pid</value>
  346.  
  347. Error log file
  348. <value name="error_log">/usr/local/webserver/php/logs/php-fpm.log</value>
  349.  
  350. Log level
  351. <value name="log_level">notice</value>
  352.  
  353. When this amount of php processes exited with SIGSEGV or SIGBUS ...
  354. <value name="emergency_restart_threshold"></value>
  355.  
  356. ... in a less than this interval of time, a graceful restart will be initiated.
  357. Useful to work around accidental curruptions in accelerator's shared memory.
  358. <value name="emergency_restart_interval">1m</value>
  359.  
  360. Time limit on waiting child's reaction on signals from master
  361. <value name="process_control_timeout">5s</value>
  362.  
  363. Set to 'no' to debug fpm
  364. <value name="daemonize">yes</value>
  365.  
  366. </section>
  367.  
  368. <workers>
  369.  
  370. <section name="pool">
  371.  
  372. Name of pool. Used in logs and stats.
  373. <value name="name">default</value>
  374.  
  375. Address to accept fastcgi requests on.
  376. Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
  377. <value name="listen_address">127.0.0.1:</value>
  378.  
  379. <value name="listen_options">
  380.  
  381. Set listen() backlog
  382. <value name="backlog">-</value>
  383.  
  384. Set permissions for unix socket, if one used.
  385. In Linux read/write permissions must be set in order to allow connections from web server.
  386. Many BSD-derrived systems allow connections regardless of permissions.
  387. <value name="owner"></value>
  388. <value name="group"></value>
  389. <value name="mode"></value>
  390. </value>
  391.  
  392. Additional php.ini defines, specific to this pool of workers.
  393. <value name="php_defines">
  394. <value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
  395. <value name="display_errors"></value>
  396. </value>
  397.  
  398. Unix user of processes
  399. <value name="user">www</value>
  400.  
  401. Unix group of processes
  402. <value name="group">www</value>
  403.  
  404. Process manager settings
  405. <value name="pm">
  406.  
  407. Sets style of controling worker process count.
  408. Valid values are 'static' and 'apache-like'
  409. <value name="style">static</value>
  410.  
  411. Sets the limit on the number of simultaneous requests that will be served.
  412. Equivalent to Apache MaxClients directive.
  413. Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
  414. Used with any pm_style.
  415. <value name="max_children"></value>
  416.  
  417. Settings group for 'apache-like' pm style
  418. <value name="apache_like">
  419.  
  420. Sets the number of server processes created on startup.
  421. Used only when 'apache-like' pm_style is selected
  422. <value name="StartServers"></value>
  423.  
  424. Sets the desired minimum number of idle server processes.
  425. Used only when 'apache-like' pm_style is selected
  426. <value name="MinSpareServers"></value>
  427.  
  428. Sets the desired maximum number of idle server processes.
  429. Used only when 'apache-like' pm_style is selected
  430. <value name="MaxSpareServers"></value>
  431.  
  432. </value>
  433.  
  434. </value>
  435.  
  436. The timeout (in seconds) for serving a single request after which the worker process will be terminated
  437. Should be used when 'max_execution_time' ini option does not stop script execution for some reason
  438. '0s' means 'off'
  439. <value name="request_terminate_timeout">0s</value>
  440.  
  441. The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
  442. '0s' means 'off'
  443. <value name="request_slowlog_timeout">0s</value>
  444.  
  445. The log file for slow requests
  446. <value name="slowlog">logs/slow.log</value>
  447.  
  448. Set open file desc rlimit
  449. <value name="rlimit_files"></value>
  450.  
  451. Set max core size rlimit
  452. <value name="rlimit_core"></value>
  453.  
  454. Chroot to this directory at the start, absolute path
  455. <value name="chroot"></value>
  456.  
  457. Chdir to this directory at the start, absolute path
  458. <value name="chdir"></value>
  459.  
  460. Redirect workers' stdout and stderr into main error log.
  461. If not set, they will be redirected to /dev/null, according to FastCGI specs
  462. <value name="catch_workers_output">yes</value>
  463.  
  464. How much requests each process should execute before respawn.
  465. Useful to work around memory leaks in 3rd party libraries.
  466. For endless request processing please specify
  467. Equivalent to PHP_FCGI_MAX_REQUESTS
  468. <value name="max_requests"></value>
  469.  
  470. Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
  471. Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.+)
  472. Makes sense only with AF_INET listening socket.
  473. <value name="allowed_clients">127.0.0.1</value>
  474.  
  475. Pass environment variables like LD_LIBRARY_PATH
  476. All $VARIABLEs are taken from current environment
  477. <value name="environment">
  478. <value name="HOSTNAME">$HOSTNAME</value>
  479. <value name="PATH">/usr/local/bin:/usr/bin:/bin</value>
  480. <value name="TMP">/tmp</value>
  481. <value name="TMPDIR">/tmp</value>
  482. <value name="TEMP">/tmp</value>
  483. <value name="OSTYPE">$OSTYPE</value>
  484. <value name="MACHTYPE">$MACHTYPE</value>
  485. <value name="MALLOC_CHECK_"></value>
  486. </value>
  487.  
  488. </section>
  489.  
  490. </workers>
  491.  
  492. </configuration>
  493.   、启动php-cgi进程,监听127.0.0.19000端口,进程数为128(如果服务器内存小于3GB,可以只开启64个进程),用户为www
  494. ulimit -SHn
  495. /usr/local/webserver/php/sbin/php-fpm start
  496.  
  497.   注:/usr/local/webserver/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload
  498.  
  499.   三、安装Nginx 0.8.
  500.   、安装Nginx所需的pcre库:
  501. tar zxvf pcre-8.10.tar.gz
  502. cd pcre-8.10/
  503. ./configure
  504. make && make install
  505. cd ../
  506.  
  507.   、安装Nginx
  508. tar zxvf nginx-0.8..tar.gz
  509. cd nginx-0.8./
  510. ./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
  511. make && make install
  512. cd ../
  513.  
  514.   、创建Nginx日志目录
  515. mkdir -p /data1/logs
  516. chmod +w /data1/logs
  517. chown -R www:www /data1/logs
  518.  
  519.   、创建Nginx配置文件
  520.   ①、在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件:
  521. rm -f /usr/local/webserver/nginx/conf/nginx.conf
  522. vi /usr/local/webserver/nginx/conf/nginx.conf
  523.  
  524.   输入以下内容:
  525. 引用
  526. user www www;
  527.  
  528. worker_processes ;
  529.  
  530. error_log /data1/logs/nginx_error.log crit;
  531.  
  532. pid /usr/local/webserver/nginx/nginx.pid;
  533.  
  534. #Specifies the value for maximum file descriptors that can be opened by this process.
  535. worker_rlimit_nofile ;
  536.  
  537. events
  538. {
  539. use epoll;
  540. worker_connections ;
  541. }
  542.  
  543. http
  544. {
  545. include mime.types;
  546. default_type application/octet-stream;
  547.  
  548. #charset gb2312;
  549.  
  550. server_names_hash_bucket_size ;
  551. client_header_buffer_size 32k;
  552. large_client_header_buffers 32k;
  553. client_max_body_size 8m;
  554.  
  555. sendfile on;
  556. tcp_nopush on;
  557.  
  558. keepalive_timeout ;
  559.  
  560. tcp_nodelay on;
  561.  
  562. fastcgi_connect_timeout ;
  563. fastcgi_send_timeout ;
  564. fastcgi_read_timeout ;
  565. fastcgi_buffer_size 64k;
  566. fastcgi_buffers 64k;
  567. fastcgi_busy_buffers_size 128k;
  568. fastcgi_temp_file_write_size 128k;
  569.  
  570. gzip on;
  571. gzip_min_length 1k;
  572. gzip_buffers 16k;
  573. gzip_http_version 1.0;
  574. gzip_comp_level ;
  575. gzip_types text/plain application/x-javascript text/css application/xml;
  576. gzip_vary on;
  577.  
  578. #limit_zone crawler $binary_remote_addr 10m;
  579.  
  580. server
  581. {
  582. listen ;
  583. server_name blog.zyan.cc;
  584. index index.html index.htm index.php;
  585. root /data0/htdocs/blog;
  586.  
  587. #limit_conn crawler ;
  588.  
  589. location ~ .*\.(php|php5)?$
  590. {
  591. #fastcgi_pass unix:/tmp/php-cgi.sock;
  592. fastcgi_pass 127.0.0.1:;
  593. fastcgi_index index.php;
  594. include fcgi.conf;
  595. }
  596.  
  597. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  598. {
  599. expires 30d;
  600. }
  601.  
  602. location ~ .*\.(js|css)?$
  603. {
  604. expires 1h;
  605. }
  606.  
  607. log_format access '$remote_addr - $remote_user [$time_local] "$request" '
  608. '$status $body_bytes_sent "$http_referer" '
  609. '"$http_user_agent" $http_x_forwarded_for';
  610. access_log /data1/logs/access.log access;
  611. }
  612.  
  613. server
  614. {
  615. listen ;
  616. server_name www.zyan.cc;
  617. index index.html index.htm index.php;
  618. root /data0/htdocs/www;
  619.  
  620. location ~ .*\.(php|php5)?$
  621. {
  622. #fastcgi_pass unix:/tmp/php-cgi.sock;
  623. fastcgi_pass 127.0.0.1:;
  624. fastcgi_index index.php;
  625. include fcgi.conf;
  626. }
  627.  
  628. log_format wwwlogs '$remote_addr - $remote_user [$time_local] "$request" '
  629. '$status $body_bytes_sent "$http_referer" '
  630. '"$http_user_agent" $http_x_forwarded_for';
  631. access_log /data1/logs/wwwlogs.log wwwlogs;
  632. }
  633.  
  634. server
  635. {
  636. listen ;
  637. server_name status.blog.zyan.cc;
  638.  
  639. location / {
  640. stub_status on;
  641. access_log off;
  642. }
  643. }
  644. }
  645.  
  646.   ②、在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件:
  647. vi /usr/local/webserver/nginx/conf/fcgi.conf
  648.  
  649.   输入以下内容:
  650. 引用
  651. fastcgi_param GATEWAY_INTERFACE CGI/1.1;
  652. fastcgi_param SERVER_SOFTWARE nginx;
  653.  
  654. fastcgi_param QUERY_STRING $query_string;
  655. fastcgi_param REQUEST_METHOD $request_method;
  656. fastcgi_param CONTENT_TYPE $content_type;
  657. fastcgi_param CONTENT_LENGTH $content_length;
  658.  
  659. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  660. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  661. fastcgi_param REQUEST_URI $request_uri;
  662. fastcgi_param DOCUMENT_URI $document_uri;
  663. fastcgi_param DOCUMENT_ROOT $document_root;
  664. fastcgi_param SERVER_PROTOCOL $server_protocol;
  665.  
  666. fastcgi_param REMOTE_ADDR $remote_addr;
  667. fastcgi_param REMOTE_PORT $remote_port;
  668. fastcgi_param SERVER_ADDR $server_addr;
  669. fastcgi_param SERVER_PORT $server_port;
  670. fastcgi_param SERVER_NAME $server_name;
  671.  
  672. # PHP only, required if PHP was built with --enable-force-cgi-redirect
  673. fastcgi_param REDIRECT_STATUS ;
  674.  
  675.   、启动Nginx
  676. ulimit -SHn
  677. /usr/local/webserver/nginx/sbin/nginx
  678.  
  679.   四、配置开机自动启动Nginx + PHP
  680. vi /etc/rc.local
  681.  
  682.   在末尾增加以下内容:
  683. 引用
  684. ulimit -SHn
  685. /usr/local/webserver/php/sbin/php-fpm start
  686. /usr/local/webserver/nginx/sbin/nginx
  687.  
  688.   五、优化Linux内核参数
  689. vi /etc/sysctl.conf
  690.  
  691.   在末尾增加以下内容:
  692. 引用
  693. # Add
  694. net.ipv4.tcp_max_syn_backlog =
  695. net.core.netdev_max_backlog =
  696. net.core.somaxconn =
  697.  
  698. net.core.wmem_default =
  699. net.core.rmem_default =
  700. net.core.rmem_max =
  701. net.core.wmem_max =
  702.  
  703. net.ipv4.tcp_timestamps =
  704. net.ipv4.tcp_synack_retries =
  705. net.ipv4.tcp_syn_retries =
  706.  
  707. net.ipv4.tcp_tw_recycle =
  708. #net.ipv4.tcp_tw_len =
  709. net.ipv4.tcp_tw_reuse =
  710.  
  711. net.ipv4.tcp_mem =
  712. net.ipv4.tcp_max_orphans =
  713.  
  714. #net.ipv4.tcp_fin_timeout =
  715. #net.ipv4.tcp_keepalive_time =
  716. net.ipv4.ip_local_port_range =
  717.  
  718.   使配置立即生效:
  719. /sbin/sysctl -p
  720.  
  721.   六、在不停止Nginx服务的情况下平滑变更Nginx配置
  722.   、修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:
  723. /usr/local/webserver/nginx/sbin/nginx -t
  724.  
  725.   如果屏幕显示以下两行信息,说明配置文件正确:
  726.   the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
  727.   the configuration file /usr/local/webserver/nginx/conf/nginx.conf was tested successfully
  728.  
  729.   、平滑重启:
  730.   ①、对于Nginx 0.8.x版本,现在平滑重启Nginx配置非常简单,执行以下命令即可:
  731. /usr/local/webserver/nginx/sbin/nginx -s reload
  732.  
  733.   ②、对于Nginx 0.8.x之前的版本,平滑重启稍微麻烦一些,按照以下步骤进行即可。输入以下命令查看Nginx主进程号:
  734. ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
  735.  
  736.   屏幕显示的即为Nginx主进程号,例如:
  737.   
  738.   这时,执行以下命令即可使修改过的Nginx配置文件生效:
  739. kill -HUP
  740.  
  741.   或者无需这么麻烦,找到NginxPid文件:
  742. kill -HUP `cat /usr/local/webserver/nginx/nginx.pid`
  743.  
  744.   七、编写每天定时切割Nginx日志的脚本
  745.   、创建脚本/usr/local/webserver/nginx/sbin/cut_nginx_log.sh
  746. vi /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
  747.  
  748.   输入以下内容:
  749. 引用
  750. #!/bin/bash
  751. # This script run at :
  752.  
  753. # The Nginx logs path
  754. logs_path="/usr/local/webserver/nginx/logs/"
  755.  
  756. mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
  757. mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
  758. kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`
  759.  
  760.   、设置crontab,每天凌晨00:00切割nginx访问日志
  761. crontab -e
  762.  
  763.   输入以下内容:
  764. 引用
  765. * * * /bin/bash /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
  766.  
  767.   本文若有小的修改,会第一时间在以下网址发布:
  768.   http://blog.zyan.cc/nginx_php_v6/
  769.  
  770.   附:文章修改历史
  771.  
  772.    [20100304日] [Version 6.0] 新建
  773.  
  774.    [20100416日] [Version 6.1] Nginx版本升级到0.8.35
  775.  
  776.    [20100514日] [Version 6.2] Nginx版本升级到0.8.36MySQL版本升级到5.5.3-m3my.cnf配置文件中的thread_concurrencymaster-connect-retry参数在新版本中不支持,已经注释掉。
  777.  
  778.    [20100726日] [Version 6.3] Nginx版本升级到0.8.46PHP版本升级到5.2.14。其他软件也做了相应的升级。开启php.ini中的cgi.fix_pathinfo=,防止Nginx文件类型错误解析漏洞。
  779.  
  780.   (全文完)

Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版)[原创]的更多相关文章

  1. Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器[摘抄]

    [文章作者:张宴 本文版本:v6.3 最后修改:2010.07.26 转载请注明原文链接:http://blog.s135.com/nginx_php_v6/] 前言:本文是我撰写的关于搭建“Ngin ...

  2. Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版)

    前言:本文是我撰写的关于搭建“Nginx + PHP(FastCGI)”Web服务器的第6篇文章.本系列文章作为国内最早详细介绍 Nginx + PHP 安装.配置.使用的资料之一,为推动 Nginx ...

  3. Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版)(转)

    转自:http://blog.s135.com/nginx_php_v6/] 前言:本文是我撰写的关于搭建“Nginx + PHP(FastCGI)”Web服务器的第6篇文章.本系列文章作为国内最早详 ...

  4. Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器

    [文章作者:张宴 本文版本:v6.3 最后修改:2010.07.26 转载请注明原文链接:http://blog.zyan.cc/nginx_php_v6/] 前言:本文是我撰写的关于搭建“Nginx ...

  5. Nginx:承受3万并发连接数,胜过Apache 10倍

    编者按:Nginx是目前比较重要的开源性负载均衡技术,新浪.网易.六间房等很多网站都将Nginx部署进自己的网站系统架构,并解决部分问题.本文是作者长期的实战经验,很有参考价值. 本文是我撰写的关于搭 ...

  6. Nginx系列2:用Nginx搭建一个可用的静态资源Web服务器

    上一节中编译好自己的nginx服务器后, 现在要对nginx.conf文件进行配置,搭建一个可用的静态资源Web服务器 1.放入可访问的html文件到nginx文件夹下,如图1所示: 这里我放入的是一 ...

  7. 使用nginx搭建一个可用的静态资源web服务器

    新建dlib目录,dlib里面放着很多index.html文件 修改conf文件 配置location,/所有的请求,这里一般使用alias,这样url后面的路径和dlib/下面的路径是一一对应的,如 ...

  8. Nginx 0.7.x + PHP 5.2.6(FastCGI)+ MySQL 5.1 在128M小内存VPS服务器上的配置优化

    对其用户和应用程序来讲,每一个VPS平台的运行和管理都与一台独立主机完全相同,因为每一个VPS均可独立进行重启并拥有自己的root访问权限.用户.IP地址.内存.过程.文件.应用程序.系统函数库以及配 ...

  9. [转]三大WEB服务器对比分析(apache ,lighttpd,nginx)

    原博文地址:http://www.blogjava.net/daniel-tu/archive/2008/12/29/248883.html 一.软件介绍(apache  lighttpd  ngin ...

随机推荐

  1. JQuery 动态提交form

    function exportExcel() { var merchantName = $('#merchantName').val(); var merchantNo = $('#merchantN ...

  2. sqlserver 汉字转拼音

    作者不详       --方法一sqlserver汉字转拼音首字母 --调用方法 select dbo.procGetPY ('中國') Create FUNCTION dbo.procGetPY ( ...

  3. linux系统的磁盘挂载

    1.查看数据盘在没有分区和格式化数据盘之前,使用 “df –h”命令,是无法看到数据盘的,可以使用“fdisk -l”命令查看.如下图:2. 对数据盘进行分区执行“fdisk /dev/xvdb”命令 ...

  4. OpenCV学习(4) Mat的基本操作(1)

          图像在OpenCV中都是通过Mat类来存储的,Mat可以用来表示N维矩阵,当然用的最多的还是二维矩阵.       Mat类有两部分组成:第一部分是头信息,这些信息主要用来描述矩阵,比如矩 ...

  5. [Todo] Redis里面队列的两种模式,以及抢红包在Redis中的实现

    两种队列模式: 一种是利用list的lpush/rpop等 另一种是redis自带的发布者/订阅者模式 http://www.cnblogs.com/alazalazalaz/p/5512258.ht ...

  6. python爬虫——利用BeautifulSoup4爬取糗事百科的段子

    import requests from bs4 import BeautifulSoup as bs #获取单个页面的源代码网页 def gethtml(pagenum): url = 'http: ...

  7. 【实践】简洁大方的summernote 富文本编辑器插件的用发——小技巧

    前面说到summernote 的上传,可是我要知道怎么获取内容呀,很简单调用一下函数便可: 获取内容: $("#user-work-content").summernote(&qu ...

  8. 机器学习学习笔记之一:K最近邻算法(KNN)

    算法 假定数据有M个特征,则这些数据相当于在M维空间内的点 \[X = \begin{pmatrix} x_{11} & x_{12} & ... & x_{1M} \\ x_ ...

  9. javaWeb注册,登陆,注销功能的实现

    一:注册页面:regist.jsp: <%@ page language="java" contentType="text/html; charset=UTF-8& ...

  10. 算法笔记_152:算法提高 扶老奶奶过街(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 一共有5个红领巾,编号分别为A.B.C.D.E,老奶奶被他们其中一个扶过了马路. 五个红领巾各自说话: A :我和E都没有扶老奶奶 B :老奶奶是被 ...