香港演员朱虹还活着吗:Linux Nginx安装编译MySQL 5.1.34扩展库及Php Web服务器

来源:百度文库 编辑:九乡新闻网 时间:2024/07/14 01:35:14

Linux Nginx安装编译MySQL 5.1.34扩展库及Php Web服务器

2010-02-04 13:19 佚名 CSDN 我要评论(0) 字号:T | T

本文是W3CGROUP在成功架设Linux Nginx+Php Web服务器之后的一个总结,成功设置Linux Nginx开启多域名多站点,并且不会出现502 Bad Gateway错误!本文测试环境如下:

AD:

 

特别值得一提的是Linux Nginx有很多值得学习的地方,这里我们主要介绍LinuxNginx安装编译,包括介绍Linux Nginx等方面。Linux Nginx ("engine x") 是一个高性能的 HTTP 和反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器 。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。Igor 将源代码以类BSD许可证的形式发布。尽管还是测试版,但是,Nginx已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。

本文是W3CGROUP在成功架设Linux Nginx+Php Web服务器之后的一个总结,成功设置Linux Nginx开启多域名多站点,并且不会出现502 Bad Gateway错误!本文测试环境如下:

系统环境Linux version 2.6.9(CentOS release4.7(Final))软件环境nginx-0.6.35.tar.gz当前稳定版: Nginx 0.6.35(2009年1月26日)官方Wiki:http://wiki.nginx.org官方下载:http://sysoev.ru/nginx/nginx-0.6.35.tar.gzphp-5.2.9.tar.gz官方下载:http://www.php.net/get/php-5.2.9.tar.gz/from/this/mirrorphp-5.2.9-fpm-0.5.10.diff.gz官方下载:http://php-fpm.anight.org/downloads/archive/mysql-5.1.34.tar.gzlibiconv-1.13.tar.gzlibmcrypt-2.5.8.tar.gzmcrypt-2.6.8.tar.gzmhash-0.9.9.9.tar.gz
Nginx0.6.35+Php5.2.9所有相关安装包下载 http://www.w3cgroup.com/code/nginx_php.rar

Linux Nginx安装步骤

一、 编译安装PHP5.2.9所需的支持库

  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 ../  
  7.  
  8. tar zxvf libmcrypt-2.5.8.tar.gz  
  9. cd libmcrypt-2.5.8/  
  10. ./configure  
  11. make  
  12. make install  
  13. /sbin/ldconfig  
  14. cd libltdl/  
  15. ./configure --enable-ltdl-install  
  16. make  
  17. make install  
  18. cd http://www.cnblogs.com/  
  19.  
  20. tar zxvf mhash-0.9.9.9.tar.gz  
  21. cd mhash-0.9.9.9/  
  22. ./configure  
  23. make  
  24. make install  
  25. cd ../  
  26.  
  27. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la  
  28. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so  
  29. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4  
  30. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8  
  31. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a  
  32. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la  
  33. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so  
  34. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2  
  35. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1  
  36.  
  37. tar zxvf mcrypt-2.6.8.tar.gz  
  38. cd mcrypt-2.6.8/  
  39. /sbin/ldconfig  
  40. ./configure  
  41. make  
  42. make install  
  43. cd ../ 

二、Linux Nginx编译安装MySQL 5.1.34扩展库

  1. /usr/sbin/groupadd mysql  
  2. /usr/sbin/useradd -g mysql mysql  
  3. tar zxvf mysql-5.1.34.tar.gz  
  4. cd mysql-5.1.34/  
  5. ./configure --prefix=/usr/local/webserver/mysql/   
  6. --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables   
  7. --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase 
  8. make && make install  
  9. chmod +w /usr/local/webserver/mysql  
  10. chown -R mysql:mysql /usr/local/webserver/mysql  
  11. cd ../ 

MySql的安装此处就省略

三、Linux Nginx编译安装PHP(FastCGI模式)

  1. tar zxvf php-5.2.9.tar.gz  
  2. gzip -cd php-5.2.9-fpm-0.5.10.diff.gz | patch -d php-5.2.9 -p1  
  3. cd php-5.2.9/  
  4. ./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc  
  5. --with-mysql=/usr/local/webserver/mysql   
  6. --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-iconv-dir=/usr/local  
  7.  --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib   
  8. --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path   
  9. --enable-safe-mode --enable-bcmath   
  10. --enable-shmop --enable-sysvsem --enable-inline-optimization   
  11. --with-curl --with-curlwrappers --enable-mbregex  
  12.  --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring  
  13.  --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash  
  14.  --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl  
  15. make ZEND_EXTRA_LIBS='-liconv' 
  16. make install  
  17. cp php.ini-dist /usr/local/webserver/php/etc/php.ini  
  18. cd ../ 


四、Linux Nginx修改php-fpm配置文件

  1. rm -f /usr/local/webserver/php/etc/php-fpm.conf  
  2. vi /usr/local/webserver/php/etc/php-fpm.conf 

输入以下内容:

  1.  version="1.0" ?>   
  2.    
  3.  name="global_options">   
  4.  name="pid_file">/usr/local/webserver/php/logs/php-fpm.pid   
  5.  name="error_log">/usr/local/webserver/php/logs/php-fpm.log   
  6.  name="log_level">notice   
  7.  name="emergency_restart_threshold">10   
  8.  name="emergency_restart_interval">1m   
  9.  name="process_control_timeout">5s   
  10.  name="daemonize">yes   
  11.    
  12.    
  13.  name="pool">   
  14.  name="name">default   
  15.  name="listen_address">127.0.0.1:9000   
  16.  name="listen_options">   
  17.  name="backlog">-1   
  18.  name="owner">   
  19.  name="group">   
  20.  name="mode">0666   
  21.    
  22.  name="php_defines">   
  23.  name="sendmail_path">/usr/sbin/sendmail -t -i   
  24.  name="display_errors">1   
  25.    
  26.  name="user">www   
  27.  name="group">www   
  28.  name="pm">   
  29.  name="style">static   
  30.  name="max_children">128   
  31.  name="apache_like">   
  32.  name="StartServers">20   
  33.  name="MinSpareServers">5   
  34.  name="MaxSpareServers">35   
  35.    
  36.    
  37.  name="request_terminate_timeout">0s   
  38.  name="request_slowlog_timeout">0s   
  39.  name="slowlog">logs/slow.log   
  40.  name="rlimit_files">51200   
  41.  name="rlimit_core">0   
  42.  name="chroot">   
  43.  name="chdir">   
  44.  name="catch_workers_output">yes   
  45.  name="max_requests">500   
  46.  name="allowed_clients">127.0.0.1   
  47.  name="environment">   
  48.  name="HOSTNAME">$HOSTNAME   
  49.  name="PATH">/usr/local/bin:/usr/bin:/bin   
  50.  name="TMP">/tmp   
  51.  name="TMPDIR">/tmp   
  52.  name="TEMP">/tmp   
  53.  name="OSTYPE">$OSTYPE   
  54.  name="MACHTYPE">$MACHTYPE   
  55.  name="MALLOC_CHECK_">2   
  56.    
  57.    
  58.    
  59.  

五、Linux Nginx创建www用户组及www用户

  1. /usr/sbin/groupadd www  
  2. /usr/sbin/useradd -g www www 


六、编译安装Linux Nginx

tar zxvf nginx-0.6.35.tar.gz cd nginx-0.6.35/默认安装:./configuremake&& make install默认情况下,Nginx 会被安装在/usr/local/nginx。通过设定编译选项,你可以改变这个设定。

指定编译选项安装,如:./configure --user=www --group=www--prefix=/usr/local/webserver/nginx --with-http_stub_status_module--with-http_ssl_modulemake && make install cd ../

七、Linux Nginx创建fcgi.conf文件

  1. rm -f /usr/local/webserver/nginx/conf/fcgi.conf  
  2. vi /usr/local/webserver/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; 

八、编辑Linux Nginx配置文件

  1. rm -f /usr/local/webserver/nginx/conf/nginx.conf  
  2. vi /usr/local/webserver/nginx/conf/nginx.conf 

输入以下内容:

  1. user www www;  
  2. worker_processes 8;  
  3. error_log /usr/local/webserver/nginx/logs/logs/nginx_error.log crit;  
  4. pid /usr/local/webserver/nginx/logs/nginx.pid;  
  5. worker_rlimit_nofile 51200;  
  6. events {  
  7. use epoll;  
  8. worker_connections 51200;  
  9. }  
  10.  
  11. http {  
  12. include mime.types;  
  13. default_type application/octet-stream;  
  14. charset utf-8;  
  15.  
  16. server_names_hash_bucket_size 128;  
  17. client_header_buffer_size 32k;  
  18. large_client_header_buffers 4 32k;  
  19. client_max_body_size 8m;  
  20.  
  21. sendfile on;  
  22. tcp_nopush on;  
  23. keepalive_timeout 60;  
  24. tcp_nodelay on;  
  25.  
  26. fastcgi_connect_timeout 300;  
  27. fastcgi_send_timeout 300;  
  28. fastcgi_read_timeout 300;  
  29. fastcgi_buffer_size 64k;  
  30. fastcgi_buffers 8 64k;  
  31. fastcgi_busy_buffers_size 128k;  
  32. fastcgi_temp_file_write_size 128k;  
  33.  
  34. gzip on;  
  35. gzip_min_length 1k;  
  36. gzip_buffers 4 16k;  
  37. gzip_http_version 1.0;  
  38. gzip_comp_level 2;  
  39. gzip_types text/plain application/x-javascript text/css application/xml;  
  40. gzip_vary on;  
  41.  
  42. #limit_zone crawler $binary_remote_addr 10m;  
  43. #多个站点设置,站点文件夹必须放在Nginx的html目录,否则不支持多站点  
  44. server {  
  45. listen 80;  
  46. server_name www.v-ec.com;  
  47. root /usr/local/webserver/nginx/html/www.v-ec.com;  
  48. index index.php index.html;  
  49.  
  50. location ~ .*\.(php|php5)?$ {   
  51. #fastcgi_pass unix:/tmp/php-cgi.sock;  
  52. fastcgi_pass 127.0.0.1:9000;  
  53. fastcgi_index index.php;  
  54. include fcgi.conf;  
  55. }  
  56.  
  57. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {  
  58. expires 30d;  
  59. }  
  60.  
  61. location ~ .*\.(js|css)?$ {  
  62. expires 6h;  
  63. }  
  64.  
  65. log_format veclog '$remote_addr - $remote_user [$time_local] "$request" '  
  66. '$status $body_bytes_sent "$http_referer" '  
  67. '"$http_user_agent" $http_x_forwarded_for';  
  68. access_log logs/vec.log veclog;  
  69. }  
  70. #多个站点设置,站点文件夹必须放在Nginx的html目录,否则不支持多站点  
  71. server {  
  72. listen 80;  
  73. server_name www.w3cgroup.com;  
  74. root /usr/local/webserver/nginx/html/www.w3cgroup.com;  
  75. index index.php index.html;  
  76.  
  77. location ~ .*\.(php|php5)?$ {   
  78. #fastcgi_pass unix:/tmp/php-cgi.sock;  
  79. fastcgi_pass 127.0.0.1:9000;  
  80. fastcgi_index index.php;  
  81. include fcgi.conf;  
  82. }  
  83.  
  84. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {  
  85. expires 30d;  
  86. }  
  87.  
  88. location ~ .*\.(js|css)?$ {  
  89. expires 6h;  
  90. }  
  91.  
  92. log_format w3cclog '$remote_addr - $remote_user [$time_local] "$request" '  
  93. '$status $body_bytes_sent "$http_referer" '  
  94. '"$http_user_agent" $http_x_forwarded_for';  
  95. access_log logs/w3c.log w3clog;  
  96. }  

九、配置开机自动启动Linux Nginx + PHP

  1. vi /etc/rc.local 

在末尾增加以下内容:

  1. ulimit -SHn 51200  
  2. /usr/local/webserver/php/sbin/php-fpm start  
  3. /usr/local/webserver/nginx/sbin/nginx 

十、Linux Nginx优化Linux内核参数

  1. vi /etc/sysctl.conf 

在末尾增加以下内容:

  1. net.ipv4.tcp_fin_timeout = 30 
  2. net.ipv4.tcp_keepalive_time = 300 
  3. net.ipv4.tcp_syncookies = 1 
  4. net.ipv4.tcp_tw_reuse = 1 
  5. net.ipv4.tcp_tw_recycle = 1 

使配置立即生效:/sbin/sysctl –p做到这里,可以reboot重启Linux了,不出意外的话应该可以顺利开启Nginx