nginx + apache + php + mysql

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
云数据库 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  '$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,如需转载请自行联系原作者
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
|
9月前
|
数据可视化 关系型数据库 MySQL
ELK实现nginx、mysql、http的日志可视化实验
通过本文的步骤,你可以成功配置ELK(Elasticsearch, Logstash, Kibana)来实现nginx、mysql和http日志的可视化。通过Kibana,你可以直观地查看和分析日志数据,从而更好地监控和管理系统。希望这些步骤能帮助你在实际项目中有效地利用ELK来处理日志数据。
666 90
|
8月前
|
Ubuntu PHP
Ubuntu下使用apt为Apache2编译PHP7.1
以上就是在Ubuntu系统下,使用apt为Apache2编译PHP7.1的过程。希望这个过程对你有所帮助,如果你在执行过程中遇到任何问题,都可以在网上找到相关的解决方案。
157 25
|
8月前
|
Ubuntu PHP Apache
在Ubuntu系统中为apt的apache2编译PHP 7.1的方法
以上就是在Ubuntu系统中为apt的apache2编译PHP 7.1的方法。希望这个指南能帮助你成功编译PHP 7.1,并在你的Apache服务器上运行PHP应用。
192 28
|
8月前
|
关系型数据库 MySQL Linux
查看Linux、Apache、MySQL、PHP版本的技巧
以上就是查看Linux、Apache、MySQL、PHP版本信息的方法。希望这些信息能帮助你更好地理解和使用你的LAMP技术栈。
392 17
|
数据库连接 PHP Apache
PHP在Apache中如何运行?
PHP在Apache中如何运行?
431 5
|
SQL DataWorks 关系型数据库
阿里云 DataWorks 正式支持 SelectDB & Apache Doris 数据源,实现 MySQL 整库实时同步
阿里云数据库 SelectDB 版是阿里云与飞轮科技联合基于 Apache Doris 内核打造的现代化数据仓库,支持大规模实时数据上的极速查询分析。通过实时、统一、弹性、开放的核心能力,能够为企业提供高性价比、简单易用、安全稳定、低成本的实时大数据分析支持。SelectDB 具备世界领先的实时分析能力,能够实现秒级的数据实时导入与同步,在宽表、复杂多表关联、高并发点查等不同场景下,提供超越一众国际知名的同类产品的优秀性能,多次登顶 ClickBench 全球数据库分析性能排行榜。
584 6
|
tengine 关系型数据库 MySQL
Tengine、Nginx安装MySQL数据库命令教程
本指南详细介绍了在Linux系统上安装与配置MySQL数据库的步骤。首先通过下载并安装MySQL社区版本,接着启动MySQL服务,使用`systemctl start mysqld.service`命令。若启动失败,可尝试使用`sudo /etc/init.d/mysqld start`。利用`systemctl status mysqld.service`检查MySQL的服务状态,确保其处于运行中。通过日志文件获取初始密码,使用该密码登录数据库,并按要求更改初始密码以增强安全性。随后创建一个名为`tengine`的数据库,最后验证数据库创建是否成功以及完成整个设置流程。
|
NoSQL 关系型数据库 Redis
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
mall在linux环境下的部署(基于Docker容器),docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongodb、minio详细教程,拉取镜像、运行容器
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
|
关系型数据库 MySQL 应用服务中间件
win7系统搭建PHP+Mysql+Apache环境+部署ecshop项目
这篇文章介绍了如何在Windows 7系统上搭建PHP、MySQL和Apache环境,并部署ECShop项目,包括安装配置步骤、解决常见问题以及使用XAMPP集成环境的替代方案。
193 1
win7系统搭建PHP+Mysql+Apache环境+部署ecshop项目
|
Ubuntu 应用服务中间件 Linux
在Linux中,如何配置Web服务器(如Apache或Nginx)?
在Linux中,如何配置Web服务器(如Apache或Nginx)?

推荐镜像

更多