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

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

特别值得一提的是Linux Nginx有很多值得学习的地方,这里我们主要介绍Linux Nginx安装编译,包括介绍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 release 4.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. <?xml version="1.0" ?>   
  2. <configuration>   
  3. <section name="global_options">   
  4. <value name="pid_file">/usr/local/webserver/php/logs/php-fpm.pid</value>   
  5. <value name="error_log">/usr/local/webserver/php/logs/php-fpm.log</value>   
  6. <value name="log_level">notice</value>   
  7. <value name="emergency_restart_threshold">10</value>   
  8. <value name="emergency_restart_interval">1m</value>   
  9. <value name="process_control_timeout">5s</value>   
  10. <value name="daemonize">yes</value>   
  11. </section>   
  12. <workers>   
  13. <section name="pool">   
  14. <value name="name">default</value>   
  15. <value name="listen_address">127.0.0.1:9000</value>   
  16. <value name="listen_options">   
  17. <value name="backlog">-1</value>   
  18. <value name="owner"></value>   
  19. <value name="group"></value>   
  20. <value name="mode">0666</value>   
  21. </value>   
  22. <value name="php_defines">   
  23. <value name="sendmail_path">/usr/sbin/sendmail -t -i</value>   
  24. <value name="display_errors">1</value>   
  25. </value>   
  26. <value name="user">www</value>   
  27. <value name="group">www</value>   
  28. <value name="pm">   
  29. <value name="style">static</value>   
  30. <value name="max_children">128</value>   
  31. <value name="apache_like">   
  32. <value name="StartServers">20</value>   
  33. <value name="MinSpareServers">5</value>   
  34. <value name="MaxSpareServers">35</value>   
  35. </value>   
  36. </value>   
  37. <value name="request_terminate_timeout">0s</value>   
  38. <value name="request_slowlog_timeout">0s</value>   
  39. <value name="slowlog">logs/slow.log</value>   
  40. <value name="rlimit_files">51200</value>   
  41. <value name="rlimit_core">0</value>   
  42. <value name="chroot"></value>   
  43. <value name="chdir"></value>   
  44. <value name="catch_workers_output">yes</value>   
  45. <value name="max_requests">500</value>   
  46. <value name="allowed_clients">127.0.0.1</value>   
  47. <value name="environment">   
  48. <value name="HOSTNAME">$HOSTNAME</value>   
  49. <value name="PATH">/usr/local/bin:/usr/bin:/bin</value>   
  50. <value name="TMP">/tmp</value>   
  51. <value name="TMPDIR">/tmp</value>   
  52. <value name="TEMP">/tmp</value>   
  53. <value name="OSTYPE">$OSTYPE</value>   
  54. <value name="MACHTYPE">$MACHTYPE</value>   
  55. <value name="MALLOC_CHECK_">2</value>   
  56. </value>   
  57. </section>   
  58. </workers>   
  59. </configuration> 

五、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

【编辑推荐】

  1. Linux MYSQL命令修改各种连接的这那方法
  2. Linux MySQL程序服务内建安全机制
  3. Linux Oracle访问MySQL的Client端软件
  4. Linux mount命令于的基本用法与umount的命令
  5. Linux mount命令系统挂载与镜像处理
责任编辑:佚名 来源: CSDN
相关推荐

2021-11-24 08:00:00

服务器Web系统

2012-05-17 09:58:40

PHP

2021-12-14 16:15:47

LinuxNginxWeb

2014-07-15 09:44:07

Linux Web服务Nginx

2010-02-03 09:26:52

Linux Mysql

2012-09-19 09:47:58

PHPWeb服务器

2010-12-28 15:39:38

2020-04-15 20:57:57

NginxWeb服务器

2017-12-27 10:18:09

ApacheNginx服务器

2009-11-18 11:10:16

PHP WEB服务器

2011-02-13 12:37:09

MySQLApachePHP

2009-06-27 21:35:50

Linux服务器

2009-12-30 10:09:08

Ubuntu Apac

2011-07-07 15:43:51

服务器安装

2009-12-08 13:18:17

2014-08-04 11:22:21

linuxsamba服务器

2011-09-08 10:42:38

Web服务器Nginx

2010-03-30 18:26:07

Nginx Web服务

2022-09-07 08:47:50

NGINXLinuxWeb 服务器

2009-09-17 14:05:18

WSUS服务器
点赞
收藏

51CTO技术栈公众号