CHSHJ 发表于 2018-11-20 08:07:50

apache安装(适用于初学者)

应用系统是centos 6.xhttpd 2.2 (apache2.4版本对apr版本要求在1.4以上,

  # rpm -q apr
  apr-1.3.9-5.el6_2.x86_64
yum安装的是1.3.9版主,安装2.4版本需要源码包安装apr)


为了不影响实验效果,提前可以把selinux 和iptables 关闭

# chkconfig iptables off
# chkconfig ip6tables off
# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter         
iptables: Flushing firewall rules:                        
iptables: Unloading modules:                              
# /etc/init.d/ip6tables stop
ip6tables: Setting chains to policy ACCEPT: filter         
ip6tables: Flushing firewall rules:                        
ip6tables: Unloading modules:                              


# sed -i "s/LINUX=.*/LINUX=disabled/g" /etc/selinux/config
# grep -i --color linux /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX=disabled
#   enforcing - SELinux security policy is enforced.
#   permissive - SELinux prints warnings instead of enforcing.
#   disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
SELINUXTYPE=targeted
更改完selinux后要想生效需要重启一下服务器,reboot或者shutdown -r now



yum installgcc gcc-c++ zlib-devel pcre pcre-devel apr apr-deve
这些是支持包 为了防止报错 提前yum 一下
  

  

  1,下载
  #cd /usr/local/src/
  #wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.tar.gz(2.2版本)
  

  2,解压
  # tar zxvf httpd-2.2.31.tar.gz
  

  3,配置编译参数
  # cd httpd-2.2.31
  # ls
  ABOUT_APACHEconfig.layouthttpd.spec      LICENSE      README.platforms
  acinclude.m4configure      include         Makefile.in    README-win32.txt
  Apache.dsw    configure.in INSTALL         Makefile.win   ROADMAP
  build         docs         InstallBin.dspmodules      server
  BuildAll.dspemacs-style    LAYOUT          NOTICE         srclib
  BuildBin.dsphttpd.dep      libhttpd.dep    NWGNUmakefilesupport
  buildconf   httpd.dsp      libhttpd.dsp    os             test
  CHANGES       httpd.mak      libhttpd.mak    README         VERSIONING
  #./configure--prefix=/usr/local/apache2--with-included-apr   --enable-so--enable-deflate=shared--enable-expires=shared --enable-rewrite=shared --with-pcre
  --prefix=/usr/local/apache2指定安装位置--with-included-apr 可以跨平台
  --enable-deflate=shared--enable-expires=shared --enable-rewrite=shared --with-pcre表示以动态共享的模式安装   --with-pcre 表示正则相关的一个库
  

  4, 编译安装
  # make && make install && echo $?
  

  5 测试
  # /usr/local/apache2/bin/apachectl start(启动服务)
  # /usr/local/apache2/bin/apachectl stop    (停止当前服务)
  # /usr/local/apache2/bin/apachectl graceful (只加载配置文件)
  # ps aux | grep httpd
  root   203670.10.1   43961696 ?      Ss   18:07   0:00 /usr/local/apache2/bin/httpd -k start
  daemon   203680.00.1   43961120 ?      S    18:07   0:00 /usr/local/apache2/bin/httpd -k start
  daemon   203690.00.1   43961120 ?      S    18:07   0:00 /usr/local/apache2/bin/httpd -k start
  daemon   203700.00.1   43961120 ?      S    18:07   0:00 /usr/local/apache2/bin/httpd -k start
  daemon   203710.00.1   43961120 ?      S    18:07   0:00 /usr/local/apache2/bin/httpd -k start
  daemon   203720.00.1   43961120 ?      S    18:07   0:00 /usr/local/apache2/bin/httpd -k start
  root   203810.00.0   6056   796 pts/0    S+   18:09   0:00 grep httpd
  #netstat -lnp |grep 80
  tcp      0      0 :::80                     :::*                        LISTEN      20367/httpd
  

  

  到这里apache就安装完毕了 可以在IE里面输入ip地址访问一下 ,如果报错请检查一下selinux和iptables或者检测服务是否开启
  
  
  # /usr/local/apache2/bin/apachectl -l   (查看静态模块)
  # /usr/local/apache2/bin/apachectl -M   (查看动态模块)
  命令是不是很长啊 我们做一些修改 编辑path文件然后自定义
#vim /etc/profile.d/path.sh
# cat !$
cat /etc/profile.d/path.sh
#!/bin/bash
export PATH=$PATH:/usr/local/apache2/bin
#. /etc/profile.d/path.sh 或者 source/etc/profile.d/path.sh


  # ls /usr/local/apache2/modules/   (动态配置文件)
  httpd.expmod_deflate.somod_expires.somod_rewrite.so
  # ls /usr/local/apache2/bin/httpd    (静态配置文件)
  /usr/local/apache2/bin/httpd
  

  

  

  # apachectl start    (启动服务)
  # apachectl stop    (关闭服务)
  
  # apachectl -l   (查看静态模块)
  # apachectl -M   (查看动态模块)
  
  # apachectl -t      (检测配置文件)
  
  # ls /usr/local/apache2/conf/httpd.conf(语法配置文件)
  # vim /usr/local/apache2/htdocs/index.html (网页内容)
  这些要熟记哦



页: [1]
查看完整版本: apache安装(适用于初学者)