nginx + apache + php + mysql

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

前期的一些小工作:

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  '$remote_addr - $remote_user [$time_local] "$request" ' 
  16.                        '$status $body_bytes_sent "$http_referer" ' 
  17.                        '"$http_user_agent" "$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 $host$uri$is_args$args; 
  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,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1月前
|
Ubuntu Apache PHP
解决Ubuntu下Apache不解析PHP问题
解决Ubuntu下Apache不解析PHP问题
|
3月前
|
Java 应用服务中间件 Apache
简介Nginx,Tomcat和 Apache
简介Nginx,Tomcat和 Apache
简介Nginx,Tomcat和 Apache
|
4月前
|
关系型数据库 MySQL PHP
|
12天前
|
应用服务中间件 PHP nginx
php如何实现检测nginx配置的正确性
请确保在执行此操作时,PHP有足够的权限来执行Nginx命令和访问Nginx配置文件。另外,将上述代码嵌入到您的应用程序中时,要注意安全性,以防止潜在的命令注入攻击。
51 3
|
14天前
|
关系型数据库 MySQL PHP
【PHP 开发专栏】PHP 连接 MySQL 数据库的方法
【4月更文挑战第30天】本文介绍了 PHP 连接 MySQL 的两种主要方法:mysqli 和 PDO 扩展,包括连接、查询和处理结果的基本步骤。还讨论了连接参数设置、常见问题及解决方法,如连接失败、权限和字符集问题。此外,提到了高级技巧如使用连接池和缓存连接信息以优化性能。最后,通过实际案例分析了在用户登录系统和数据管理中的应用。
|
29天前
|
PHP
web简易开发——通过php与HTML+css+mysql实现用户的登录,注册
web简易开发——通过php与HTML+css+mysql实现用户的登录,注册
|
1月前
|
关系型数据库 MySQL Linux
Centos7 yum安装lAMP 环境 php版本5.6.38 mysql版本5.7.22
Centos7 yum安装lAMP 环境 php版本5.6.38 mysql版本5.7.22
28 0
|
2月前
|
应用服务中间件 Linux PHP
Linux下安装php环境并且配置Nginx支持php-fpm模块
Linux下安装php环境并且配置Nginx支持php-fpm模块
34 0
|
2月前
|
运维 Linux Apache
LAMP架构调优(十)——Apache禁止指定目录PHP解析与错误页面优化
LAMP架构调优(十)——Apache禁止指定目录PHP解析与错误页面优化
200 2
|
3月前
|
监控 关系型数据库 MySQL
PHP与MySQL的结合:实现局域网上网行为监控软件的数据库管理
在当今信息化时代,网络安全日益成为重要的话题。为了有效监控和管理局域网上网行为,开发一个基于PHP和MySQL的数据库管理系统是一个理想的选择。本文将介绍如何结合PHP和MySQL,开发一款简单而高效的局域网上网行为监控软件,并重点关注数据库管理方面的实现。
200 0

推荐镜像

更多