centos-6.5 安装apache
1、避免端口、程序冲突、使用rpm卸载httpd
[root@www /]# rpm -qa httpd #检查httpd的包 [root@www /]# rpm -e httpd --nodeps #卸载
2、源码编译安装
- 下载httpd包、解压
[root@www /]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.31.tar.gz [root@www /]# tar zxf httpd-2.2.31.tar.gz -C /usr/src #解压到/usr/src [root@www /]# cd /usr/src/httpd-2.2.31/
- 配置
[root@www httpd-2.2.31]# ls INSTALL README #遇到不熟悉的软件是可参考这两个文件 [root@www httpd-2.2.31]# less README [root@www httpd-2.2.31]# less INSTALL [root@www httpd-2.2.31]# ./configure --help #各种配置选项及含义 [root@www httpd-2.2.31]# yum -y install gcc [root@www httpd-2.2.31]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi --prefix #安装目录 --enable-so #启用加载状态模块 --enable-rewrite #启用网页地址重写功能 --enable-charset-lite #启用字符集支持 --enable-cgi #启用CGI脚本程序支持 [root@www httpd-2.2.31]# echo $? 0
- 编译安装
[root@www httpd-2.2.31]# make && make install # make进行编译、make install 安装 [root@www httpd-2.2.31]# echo $? 0
3、确认安装结果
[root@www httpd-2.2.31]# ls /usr/local/httpd/ bin cgi-bin error icons lib man modules build conf htdocs include logs manual
4、优化执行路径
[root@www httpd-2.2.31]# ln -s /usr/local/httpd/bin/* /usr/local/bin/ [root@www httpd-2.2.31]# ls -l /usr/local/bin/httpd /usr/local/bin/apachectl lrwxrwxrwx. 1 root root 30 Sep 27 23:49 /usr/local/bin/apachectl -> /usr/local/httpd/bin/apachectl lrwxrwxrwx. 1 root root 26 Sep 27 23:49 /usr/local/bin/httpd -> /usr/local/httpd/bin/httpd
5、添加httpd系统服务
[root@www httpd-2.2.31]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd [root@www httpd-2.2.31]# vim /etc/init.d/httpd #!/bin/sh # chkconfig:35 85 21 #3、5中启动、启动关闭的顺序分别为85、21 # description: start Apache HTTP Server #服务描述 [root@www httpd-2.2.31]# chkconfig --add httpd #添加系统服务 ch[root@www httpd-2.2.31]# chkconfig --list httpd #查看httpd服务的自启动状态 httpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
6、配置httpd服务、并启动
[root@www httpd-2.2.31]# vim /usr/local/httpd/conf/httpd.conf Servername www.httpd.com [root@www httpd-2.2.31]# /usr/local/httpd/bin/apachectl -t #语法检查 Syntax OK [root@www httpd-2.2.31]# /etc/init.d/httpd start [root@www httpd-2.2.31]# netstat -anpt | grep httpd tcp 0 0 :::80 :::* LISTEN 50141/httpd
7、访问web站点
[root@www httpd-2.2.31]# vim /etc/hosts 192.168.119.131 www.httpd.com [root@www httpd-2.2.31]# curl www.httpd.com <html><body><h1>It works!</h1></body></html>
8、查看web站点访问情况
访问日志access_log错误日志error_log [root@www httpd-2.2.31]# tail /usr/local/httpd/logs/access_log 192.168.119.131 - - [28/Sep/2016:00:05:13 +0800] "GET / HTTP/1.1" 200 44 [root@www httpd-2.2.31]# tail /usr/local/httpd/logs/error_log