nginx + apache + php + mysql

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介:

前期的一些小工作:

1)安装zlib

 
  1. # cd zlib-1.2.5 
  2. # ./configure --prefix=/usr/local/zlib 
  3. # make && make install && make clean 

2)安装openssl(我们网站支付需要ssl支持)

 
  1. # cd openssl-1.0.0d 
  2. # ./config -fPIC --prefix=/usr/local/openssl/ enable-shared 
  3. # make && make install && make clean 

3)安装curl(php中curl模块,且需启用ssl 支持)

 
  1. # cd curl-7.21.4 
  2. # ./configure --prefix=/usr/local/curl \
  3. --enable-optimize  \
  4. --disable-ipv6 \
  5. --with-ssl=/usr/local/openssl \
  6. --with-zlib=/usr/local/zlib/ 

configure之后,显示

 
  1. curl version:    7.21.4 
  2.   Host setup:      x86_64-unknown-linux-gnu 
  3.   Install prefix:  /usr/local/curl 
  4.   Compiler:        gcc 
  5.   SSL support:     enabled (OpenSSL) 
  6.   SSH support:     no      (--with-libssh2) 
  7.   zlib support:    enabled 
  8.   krb4 support:    no      (--with-krb4*) 
  9.   GSSAPI support:  no      (--with-gssapi) 
  10.   SPNEGO support:  no      (--with-spnego) 
  11.   TLS-SRP support: no      (--enable-tls-srp) 
  12.   resolver:        default (--enable-ares / --enable-threaded-resolver) 
  13.   ipv6 support:    no      (--enable-ipv6) 
  14.   IDN support:     enabled 
  15.   Build libcurl:   Shared=yesStatic=yes 
  16.   Built-in manual: enabled 
  17.   Verbose errors:  enabled (--disable-verbose) 
  18.   SSPI support:    no      (--enable-sspi) 
  19.   ca cert bundle:  /etc/pki/tls/certs/ca-bundle.crt 
  20.   ca cert path:    no 
  21.   LDAP support:    enabled (OpenLDAP) 
  22.   LDAPS support:   enabled 
  23.   RTSP support:    enabled 
  24.   RTMP support:    no      (--with-librtmp) 
  25.   Protocols:       DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP LDAPS POP3 POP3S RTSP SMTP SMTPS TELNET TFTP 

4)安装nginx(处理静态页面)

 
  1. # cd nginx-0.8.54 
  2. # groupadd www && useradd www -g www -s /sbin/nologin -d /dev/null -M -c "www"
  3. #  ./configure  --prefix=/usr/local/nginx \
  4. --user=www  \
  5. --group=www  \
  6. --with-http_ssl_module  \
  7. --with-http_sub_module  \
  8. --with-http_gzip_static_module \
  9. --with-http_stub_status_module \
  10. --without-http_fastcgi_module  \
  11. --without-mail_pop3_module  \
  12. --without-mail_imap_module  \
  13. --without-mail_smtp_module  \
  14. --with-pcre=../pcre-8.12  \
  15. --with-zlib=../zlib-1.2.5  \
  16. --with-openssl=../openssl-1.0.0d
  17. # make && make install && make clean 

注:pcre,zlib,openssl均为源码解压后的目录,这个在./configure --help的时候,有注释说明

 
  1. ./configure --help |egrep '(openssl|pcre|zlib)' 
  2.   --without-pcre                     disable PCRE library usage 
  3.   --with-pcre                        force PCRE library usage 
  4.   --with-pcre=DIR                    set path to PCRE library sources 
  5.   --with-pcre-opt=OPTIONS            set additional options for PCRE building 
  6.   --with-zlib=DIR                    set path to zlib library sources 
  7.   --with-zlib-opt=OPTIONS            set additional options for zlib building 
  8.   --with-zlib-asm=CPU                use zlib assembler sources optimized 
  9.   --with-openssl=DIR                 set path to OpenSSL library sources 
  10.   --with-openssl-opt=OPTIONS         set additional options for OpenSSL building 

configure 后的提示

 
  1. Configuration summary 
  2.   + using PCRE library: ../pcre-8.12 
  3.   + using OpenSSL library: ../openssl-1.0.0d 
  4.   + md5: using OpenSSL library 
  5.   + sha1 library is not used 
  6.   + using zlib library: ../zlib-1.2.5 
  7.  
  8.   nginx path prefix: "/usr/local/nginx" 
  9.   nginx binary file: "/usr/local/nginx/sbin/nginx" 
  10.   nginx configuration prefix: "/usr/local/nginx/conf" 
  11.   nginx configuration file: "/usr/local/nginx/conf/nginx.conf" 
  12.   nginx pid file: "/usr/local/nginx/logs/nginx.pid" 
  13.   nginx error log file: "/usr/local/nginx/logs/error.log" 
  14.   nginx http access log file: "/usr/local/nginx/logs/access.log" 
  15.   nginx http client request body temporary files: "client_body_temp" 
  16.   nginx http proxy temporary files: "proxy_temp" 
  17.   nginx http uwsgi temporary files: "uwsgi_temp" 
  18.   nginx http scgi temporary files: "scgi_temp" 

配置nginx.conf

 
  1. user www www; 
  2. worker_processes 10; 
  3. pid logs/nginx.pid; 
  4. worker_rlimit_nofile 65536; 
  5.  
  6. events { 
  7.        use epoll; 
  8.        worker_connections 51200; 
  9.  
  10. http { 
  11.      include mime.types; 
  12.      server_names_hash_bucket_size 256; 
  13.      default_type application/octet-stream; 
  14.      server_tokens off; 
  15.      log_format  main  'remoteaddrremote_user [timelocal]"request" ' 
  16.                        'statusbody_bytes_sent "$http_referer" ' 
  17.                        '"httpuseragent""http_x_forwarded_for"'; 
  18.  
  19.      sendfile on; 
  20.      tcp_nopush on; 
  21.      tcp_nodelay on; 
  22.  
  23.      keepalive_timeout 120; 
  24.  
  25.      client_header_buffer_size 256k; 
  26.      client_body_buffer_size 256k; 
  27.      client_max_body_size 50m; 
  28.      large_client_header_buffers 4 256k; 
  29.  
  30.      send_timeout 3m; 
  31.      client_header_timeout 3m; 
  32.      client_body_timeout 3m; 
  33.  
  34.      connection_pool_size 256; 
  35.      request_pool_size 4k; 
  36.      output_buffers 4 32k; 
  37.      postpone_output 1460; 
  38.  
  39.      proxy_buffering on; 
  40.      proxy_ignore_client_abort off; 
  41.      proxy_intercept_errors    on; 
  42.      proxy_next_upstream       error timeout invalid_header; 
  43.      proxy_redirect            off; 
  44.      proxy_set_header          X-Forwarded-For $remote_addr; 
  45.      proxy_connect_timeout     60; 
  46.      proxy_send_timeout        60; 
  47.      proxy_read_timeout        60; 
  48.      proxy_cache_min_uses 3; 
  49.      proxy_cache_valid any 10m; 
  50.      #proxy_cache_path          /dev/shm/proxy_cache_dir levels=1:2 keys_zone=cache:2048m inactive=1d max_size=50g
  51.      proxy_temp_path           /dev/shm/proxy_temp_dir; 
  52.  
  53.      gzip on; 
  54.      gzip_http_version 1.0; 
  55.      gzip_comp_level 8; 
  56.      gzip_types text/plain text/css application/x-javascript  text/xml application/xml; 
  57.      gzip_min_length 1000; 
  58.      gzip_buffers 4 16k; 
  59.      gzip_vary on; 
  60.  
  61.      include ../upstream/http_upstream.conf; 
  62.      include ../vhosts/http-vhosts.conf; 
  63.      error_log logs/error.log crit; 
  64.      access_log logs/access.log combined; 

 http-vhosts.conf

 
  1. server { 
  2.        listen 80 default; 
  3.        server_name xxx.xxx.xxx.xxx; 
  4.        index index.html index.htm index.php; 
  5.        root /usr/local/apache/htdocs/public_html; 
  6.        include /usr/local/nginx/newurlrewrite.conf; 
  7.  
  8.        open_file_cache max=200 inactive=2h
  9.        open_file_cache_valid 3h; 
  10.        open_file_cache_errors off; 
  11.  
           #location / { 
  12.                 #proxy_next_upstream http_502 http_504 error timeout invalid_header; 
  13.                 #proxy_cache cache; 
  14.                 #proxy_cache_valid  200 304 12h; 
  15.                 #proxy_cache_valid any 1m; 
  16.                 #proxy_cache_key hosturiisargsargs; 
  17.                 #proxy_set_header Host $host; 
  18.                 #proxy_set_header X-Forwarded-For $remote_addr; 
  19.                 #proxy_pass http://test; 
  20.                 #add_header Nginx-Cache "$upstream_cache_status from xxx.xxx.xxx.xxxx"; 
  21.                 #expires    1d; 
  22.        #} 
  23.  
  24.        location ~ \.php$ { 
  25.                   proxy_set_header   Host             $host; 
  26.                   #proxy_set_header   X-Real-IP        $remote_addr; 
  27.                   proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for; 
  28.                   #proxy_redirect     default; 
  29.                   proxy_pass http://test; 
  30.        } 

http_upstream.conf(所有php请求转向apache)

 
  1. upstream test { 
  2.          server 192.168.0.112:8080; 
  3.          #server 10.36.138.8:10001 fail_timeout=3s weight=1

配置nginx自启动,nginx编译安装后的脚本见本博客其他文章

5)安装apache(处理动态页面请求)

 
  1. # cd httpd 
  2. # ./configure --prefix=/usr/local/apache  \
  3. --enable-ssl  \
  4. --with-ssl=/usr/local/openssl/  \
  5. --enable-rewrite  \
  6. --with-zlib=/usr/local/zlib/  \
  7. --enable-mods-shared=rewrite  \
  8. –-enable-headers  \
  9. -–enable-deflate  \
  10. --enable-expires
  11. # make && make install && make clean 

配置apache,主配置文件修改(主要配置,小的不说了)

 
  1. 对php的处理
  2. <IfModule dir_module>
    DirectoryIndex index.html index.php
    </IfModule>
     
  3. AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
  4.  
  5. # Real-time info on requests and configuration 
  6. Include conf/extra/httpd-info.conf 
  7.  
  8. # Virtual hosts 
  9. Include conf/extra/httpd-vhosts.conf 
  10.  
  11. # Various default settings 
  12. Include conf/extra/httpd-default.conf 
  13.  
  14. # Server-pool management (MPM specific)
    Include conf/extra/httpd-mpm.conf

httpd.conf里面加入

 
  1. # ----------------------------- 
  2. # add by Henry He on 2011/03/30 
  3. # ----------------------------- 
  4.  
  5. # for gzip 
  6. <IfModule mod_deflate.c> 
  7. DeflateCompressionLevel 9 
  8. AddOutputFilterByType   DEFLATE text/plain application/x-httpd-php 
  9. AddOutputFilter         DEFLATE  php  css  js 
  10. </IfModule> 
  11.  
  12. # for expire 
  13. #<IfModule mod_expires.c> 
  14. #ExpiresActive on 
  15. #ExpiresDefault "access plus 14 month" 
  16. #ExpiresByType text/html "access plus 14 months" 
  17. #ExpiresByType text/css "access plus 14 months" 
  18. #ExpiresByType image/gif "access plus 14 months" 
  19. #ExpiresByType image/jpeg "access plus 14 months" 
  20. #ExpiresByType image/jpg "access plus 14 months" 
  21. #ExpiresByType image/png "access plus 14 months" 
  22. #EXpiresByType application/x-javascript "access plus 14 months" 
  23. #</IfModule> 
  24. # --------------------- end -------------------------------------- 

httpd-vhosts.conf

 
  1. NameVirtualHost 192.168.0.112:8080 
  2.  
  3. # VirtualHost example: 
  4. # Almost any Apache directive may go into a VirtualHost container. 
  5. # The first VirtualHost section is used for all requests that do not 
  6. # match a ServerName or ServerAlias in any <VirtualHost> block. 
  7. <VirtualHost 192.168.0.112:8080> 
  8.     ServerAdmin  henry@abc.com 
  9.     DocumentRoot "/usr/local/apache/htdocs/public_html" 
  10.     ServerName 192.168.0.112 
  11. </VirtualHost> 

httpd-defaults.conf

 
  1. Timeout 120 
  2. KeepAlive On 
  3. MaxKeepAliveRequests 0 
  4. KeepAliveTimeout 3 
  5. UseCanonicalName Off 
  6. AccessFileName .htaccess 
  7. ServerTokens Prod 
  8. ServerSignature Off 
  9. HostnameLookups Off 

httpd-mpm.conf

 
  1. <IfModule mpm_prefork_module> 
  2.     ServerLimit         4000 
  3.     StartServers          15 
  4.     MinSpareServers       15 
  5.     MaxSpareServers       30 
  6.     MaxClients         4000 
  7.     MaxRequestsPerChild   4000 
  8. </IfModule> 

6)php的安装

 
  1. # cd php 
  2. # ./configure --prefix=/usr/local/php  \
  3. --with-curl=/usr/local/curl \
  4. --with-openssl=/usr/local/openssl \
  5. --with-apxs2=/usr/local/apache/bin/apxs \
  6. --with-mcrypt  \
  7. --disable-ipv6  \
  8. --with-mhash  \
  9. --with-zlib=/usr/local/zlib/  \
  10. --with-mysql=/opt/mysql/  \
  11. --with-mysqli=/opt/mysql/bin/mysql_config  \
  12. --enable-inline-optimization  \
  13. --disable-debug 
  14. # make && make install && make clean 

我们的这个php还好不需要gd的支持,否则麻烦死了

配置php

 
  1. # cp php.ini-production /usr/local/php/lib/php.ini 

接着,安装php的扩展memcache,xcache,suhosin等(本博客其他文章)

编译php.ini,修改以下的参数

 
  1. session.save_handler = memcache 
  2. session.save_path = "tcp://192.168.0.10:11211" 
  3.  
  4. [suhosin]
    suhosin.get.max_value_length = 5120

本文转自dongfang_09859 51CTO博客,原文链接:http://blog.51cto.com/hellosa/540645,如需转载请自行联系原作者
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
打赏
0
0
0
0
69
分享
相关文章
如何排查和解决PHP连接数据库MYSQL失败写锁的问题
通过本文的介绍,您可以系统地了解如何排查和解决PHP连接MySQL数据库失败及写锁问题。通过检查配置、确保服务启动、调整防火墙设置和用户权限,以及识别和解决长时间运行的事务和死锁问题,可以有效地保障应用的稳定运行。
108 25
PHP与MySQL动态网站开发:从基础到实践####
本文将深入探讨PHP与MySQL的结合使用,展示如何构建一个动态网站。通过一系列实例和代码片段,我们将逐步了解数据库连接、数据操作、用户输入处理及安全防护等关键技术点。无论您是初学者还是有经验的开发者,都能从中获益匪浅。 ####
PHP与MySQL动态网站开发实战指南####
——深入探索LAMP栈下的高效数据交互与处理技巧 ####
PHP与MySQL动态网站开发实战指南####
深入探索PHP与MySQL的协同工作机制,本文旨在通过一系列实战案例,揭示构建高效、稳定且用户友好的动态网站的秘诀。从环境搭建到数据交互,再到最佳实践分享,本文为开发者提供了一条清晰的学习路径,助力其在LAMP(Linux, Apache, MySQL, PHP/Perl/Python)栈上实现技术飞跃。 ####
php实现一个简单的MySQL分页
通过本文的详细步骤和代码示例,我们实现了一个简单的PHP MySQL分页功能。主要步骤包括计算总记录数、设置分页参数、查询当前页的数据以及生成分页链接。这种分页方式适用于大多数Web应用,能够有效提升用户体验和页面响应速度。
85 4
PHP与MySQL的无缝集成:构建动态网站的艺术####
本文将深入探讨PHP与MySQL如何携手合作,为开发者提供一套强大的工具集,以构建高效、动态且用户友好的网站。不同于传统的摘要概述,本文将以一个生动的案例引入,逐步揭示两者结合的魅力所在,最终展示如何通过简单几步实现数据驱动的Web应用开发。 ####
PHP与MySQL的高效协同开发策略####
本文深入探讨了PHP与MySQL在Web开发中的协同工作机制,通过优化配置、最佳实践和高级技巧,展示了如何提升数据库交互性能,确保数据安全,并促进代码可维护性。我们将从环境搭建讲起,逐步深入到查询优化、事务管理、安全防护及性能调优等核心环节,为开发者提供一套实战驱动的解决方案框架。 ####
PHP与MySQL动态网站开发深度探索####
本文旨在为读者提供一份详尽的指南,深入剖析PHP与MySQL在动态网站开发中的应用。通过具体实例与代码解析,揭示如何高效结合这两种技术构建功能强大、响应迅速的Web应用。文章将逐一探讨PHP的基础语法、MySQL数据库管理以及二者交互的关键技巧,旨在帮助开发者提升技能,优化项目开发流程。 ####
PHP与MySQL的高效交互:从基础到实践####
本文深入探讨了PHP与MySQL数据库之间的高效交互技术,涵盖了从基础连接到高级查询优化的全过程。不同于传统的摘要概述,这里我们直接以一段精简代码示例作为引子,展示如何在PHP中实现与MySQL的快速连接与简单查询,随后文章将围绕这一核心,逐步展开详细讲解,旨在为读者提供一个从入门到精通的实战指南。 ```php <?php // 数据库配置信息 servername="localhost";username = "root"; password="password";dbname = "test_db"; // 创建连接 conn=newmysqli(se
95 0
PHP与MySQL的深度整合:构建高效动态网站####
在当今这个数据驱动的时代,掌握如何高效地从数据库中检索和操作数据是至关重要的。本文将深入探讨PHP与MySQL的深度整合方法,揭示它们如何协同工作以优化数据处理流程,提升网站性能和用户体验。我们将通过实例分析、技巧分享和最佳实践指导,帮助你构建出既高效又可靠的动态网站。无论你是初学者还是有经验的开发者,都能从中获得宝贵的见解和实用的技能。 ####
47 0

热门文章

最新文章

推荐镜像

更多
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等