LOCKLOSE 发表于 2018-10-21 07:47:37

Apache HTTP Server 编译安装

  
  ##########编译安装httpd服务器##########
  1. 安装前准备工作
  卸载httpd及相关依赖包
  # rpm -e httpd --nodeps
  2. 挂载软件光盘到/mnt目录下
  # mount /dev/sr0 /mnt
  # ls /mnt/
  awstats-7.3.tar.gzhttpd-2.2.17.tar.gz
  3. 解压httpd源码包到 /usr/src目录下
  # tar zxf httpd-2.2.17.tar.gz -C /usr/src
  # cd /usr/src/httpd-2.2.17/
  4. 设置httpd服务安装路径,启用字符集支持等
  # ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
  其各项含义:--prefix:指定httpd服务器程序安装到哪个目录下,默认放在/usr/local/apache2
  --enable-so:启用动态加载模块支持,使用httpd具有进一步扩展功能的能力
  --enable-rewrite:启用网页地址重写功能,用于网站优化及目录迁移维护
  --enable-charset-lite:启用字符集编码的网页
  --enable-cgi:启用CGI脚本程序支持,便于扩展网站的应用能力
  5. 编译及安装httpd服务
  # make && make install
  6. 确认安装结果
  # ls /usr/local/httpd/
  /usr/local/httpd/bin:存放httpd服务的各种执行程序文件,包括主程序httpd,服务控制工具apachectl等
  /usr/local/httpd/conf:存放httpd的各种配置文件,包括主配置文件httpd.conf,增强配置子目录extra等
  /usr/local/httpd/htdocs:存放网页文档,包括默认首页文件index.html等
  /usr/local/httpd/logs:存放httpd服务的日志文件
  /usr/local/httpd/modules:存放httpd服务的各种模块文件
  /usr/local/httpd/cgi-bin:存放各种cgi程序文件
  7. 优化执行路径
  # ln -s /usr/local/httpd/bin/* /usr/local/bin
  #ln -s 此命令用于创建符号链接
  # ls -l /usr/local/bin/httpd /usr/local/bin/apachectl
  8. 添加httpd系统服务
  # cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
  # vim /etc/init.d/httpd
  ---------- vim ----------
  #!/bin/sh
  #chkconfig 35 85 21//服务识别参数,在3、5中启动;启动和关闭的顺序为85、21
  #description: Startup script for the Apache HTTP Server//服务描述信息
  ……//省略部分内容
  ---------- vim ----------
  # chkconfig --add httpd
  # chkconfig --list httpd
  httpd          0:关闭1:关闭2:关闭3:启用4:关闭5:启用6:关闭
  # httpd -v//查看程序版本
  Server version: Apache/2.2.17 (Unix)
  Server built:   Oct 21 2016 05:29:07
  ##########部署web站点##########
  1. 配置并启动httpd服务
  (1)配置httpd服务
  # vim /usr/local/httpd/conf/httpd.conf
  ---------- vim ----------
  ServerName www.benet.com//找到ServerName添加完全合格域名
  ---------- vim ----------
  # httpd -t//进行配置文件语法检查
  Syntax OK//没有语法错误,将显示Syntax OK
  (2)启动httpd服务
  # /etc/init.d/httpd start
  # netstat -anpt | grep httpd
  tcp      0      0 :::80                     :::*            LISTEN      22223/httpd
  2. 部署网页文档
  # vim /usr/local/httpd/htdocs/index.html
  ---------- vim ----------
  It works!
  //此内容为网站首页内容
  ---------- vim ----------
  3. 在客户机中访问web站点
  输入www.benet.com或IP地址进行访问
  4. 查看web站点的访问日志
  # tail /usr/local/httpd/logs/access_log //查看用户访问日志
  192.168.1.3 - - "GET /test.html http/1.1" 200 194
  192.168.1.3 - - "GET /test.html http/1.1" 200 194
  # tail /usr/local/httpd/logs/error_log //查看错误日志
   Apache/2.2.17 (Unix) configured -- resuming normal operations
   SIGHUP received.Attempting to restart

页: [1]
查看完整版本: Apache HTTP Server 编译安装