neversoft 发表于 2018-11-19 10:45:12

LAMP 之二 Apache 安编译安装

  Apache 安装先去官网上下载安装包/usr/local/src/,版本不要太新,也不要太旧。

  http://mirrors.cnnic.cn/apache/httpd/
  下载之后解压
  # wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.tar.bz2
  

  # tar jxvf httpd-2.2.31.tar.bz2
  

  进入到解压目录
  # cd httpd-2.2.31
  #######################################################################################
  如果不知道怎么安装可以查看帮助
  # vim INSTALL
  

  For complete installation documentation, see docs/manual/install.html or
  http://httpd.apache.org/docs/2.2/install.html
  

  $ ./configure --prefix=PREFIX
  $ make
  $ make install
  $ PREFIX/bin/apachectl start
  #######################################################################################
  因为我是看的视频有现成的步骤(直接拷贝编译文档)
  # ./configure \
  > --prefix=/usr/local/apache2 \   #指定安装的目录
  > --with-included-apr \      #apr 是httpd 依赖的一个包(底层的包,支持Apache跨平台运行)
  > --enable-so \
  > --enable-deflate=shared \    #deflate 支持压缩的    shared 表示动态支持,下同
  > --enable-expires=shared \    #expires支持静态文件过期的一些操作
  > --enable-rewrite=shared \ #rewrite 域名重定向,伪静态。
  > --with-pcre                #pcre 是否支持正则表达式。
  这个过程中如果有出现错误,请根据报错提示,解决问题
  配置完成后
  # echo $?
  0
  输出“0”表示没有问题。接着下一步 make,但是我在安装过程中出现了一个小问题
  checking for zlib location... not found
  checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures
  # echo $?
  1
  上网寻找解决办法,有网友遇到类似问题
  http://blog.csdn.net/xinhaozheng/article/details/4221525
  似乎是没有安装zlib引起的,而似乎mod_deflate模块又是有依赖于zlib
  # yum install zlib-devel
  安装后,再次编译
  
  # echo $?
  0
  问题解决。下一步make


  

  

  # make
  make 这个过程在约2分钟,完成以后
  # echo $?            #检查有没有问题
  0
  接下来:

  # make install
  

  每一步操作完成后建议
# echo $?            #检查有没有问题
0
  至此Apache 安装完成
  ###########################################################################################
  

  启动Apache
  # /usr/local/apache2/bin/apachectl start
  

  # ls /usr/local/apache2/modules/
  httpd.expmod_deflate.somod_expires.somod_rewrite.so
  mod_deflate.somod_expires.somod_rewrite.so 这三个模块
  这三个模块,都是在编译选项中加了这三个
  # ls -l /usr/local/apache2/bin/httpd
  -rwxr-xr-x 1 root root 2262241 Sep 20 09:41 /usr/local/apache2/bin/httpd
  如果在编译里不加 shared(动态)这个三个块就会和httpd 和在一起,会使得httpd 这个文件变大。
  动态shared 会把这些文件单独拿出来生成块文件和httpd 分开。
  静态staic 会把文件聚合在一起,用不用都会加载。耗费资源。
  

  l./configure --prefix=/usr/local/apache2--with-included-apr --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared--with-pcre
  ################################################
  列出所有的模块
  # /usr/local/apache2/bin/apachectl -M   查看动态加载的模块

  

  # /usr/local/apache2/bin/apachectl -l   查看静态加载的模块

  

  /usr/local/apache2/bin/apachectl restrat :(把进程先杀掉再重新开启新的进程)
  /usr/local/apache2/bin/apachectl stop :(关闭进程)
  /usr/local/apache2/bin/apachectl graceful :(旧进程还在,只是重新加载了配置文件)
  

  # /usr/local/apache2/bin/apachectl -t查看配置文件有没有语法错误
  httpd: apr_sockaddr_info_get() failed for OBird
  httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
  Syntax OK

  # ls /usr/local/apache2/conf/httpd.conf配置文件路径
  /usr/local/apache2/conf/httpd.conf
  

  # ./configure --help |less查看帮助
  指定工作模式
  --with-mpm=MPM          Choose the process model for Apache to use.
  MPM={beos|event|worker|prefork|mpmt_os2|winnt}
  worker|prefork这两种是我们常用的工作模式
  2.4 的版本不指定的,黙认的是 event 模式
  2.2 的版本不指定的,黙认的是 prefork 模式
  




页: [1]
查看完整版本: LAMP 之二 Apache 安编译安装