centos-6.5 安装apache

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos-6.5 安装apache相关的知识,希望对你有一定的参考价值。

1、避免端口、程序冲突、使用rpm卸载httpd

[[email protected] /]# rpm -qa httpd        #检查httpd的包
[[email protected] /]# rpm -e httpd --nodeps    #卸载

2、源码编译安装

  • 下载httpd包、解压
[[email protected] /]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.31.tar.gz
[[email protected] /]# tar zxf httpd-2.2.31.tar.gz -C /usr/src   #解压到/usr/src
[[email protected] /]# cd /usr/src/httpd-2.2.31/

 

  • 配置
[[email protected] httpd-2.2.31]# ls INSTALL README  #遇到不熟悉的软件是可参考这两个文件
[[email protected] httpd-2.2.31]# less README
[[email protected] httpd-2.2.31]# less INSTALL 
[[email protected] httpd-2.2.31]# ./configure --help  #各种配置选项及含义
[[email protected] httpd-2.2.31]# yum -y install gcc
[[email protected] 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脚本程序支持
[[email protected] httpd-2.2.31]# echo $?
0

 

  • 编译安装
[[email protected] httpd-2.2.31]# make && make install   # make进行编译、make install 安装
[[email protected] httpd-2.2.31]# echo $?
0

 

3、确认安装结果

[[email protected] httpd-2.2.31]# ls /usr/local/httpd/
bin    cgi-bin  error   icons    lib   man     modules
build  conf     htdocs  include  logs  manual

 

4、优化执行路径

[[email protected] httpd-2.2.31]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[[email protected] 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系统服务

[[email protected] httpd-2.2.31]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[[email protected] httpd-2.2.31]# vim /etc/init.d/httpd 
#!/bin/sh
# chkconfig:35 85 21  #3、5中启动、启动关闭的顺序分别为85、21
# description: start Apache HTTP Server  #服务描述
[[email protected] httpd-2.2.31]# chkconfig --add httpd  #添加系统服务
ch[[email protected] 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服务、并启动

[[email protected] httpd-2.2.31]# vim /usr/local/httpd/conf/httpd.conf
Servername www.httpd.com
[[email protected] httpd-2.2.31]# /usr/local/httpd/bin/apachectl -t #语法检查
Syntax OK
[[email protected] httpd-2.2.31]# /etc/init.d/httpd start
[[email protected] httpd-2.2.31]# netstat -anpt | grep httpd
tcp        0      0 :::80                       :::*                        LISTEN      50141/httpd     

 

7、访问web站点

[[email protected] httpd-2.2.31]# vim /etc/hosts
192.168.119.131  www.httpd.com
[[email protected] httpd-2.2.31]# curl www.httpd.com
<html><body><h1>It works!</h1></body></html>

 

8、查看web站点访问情况

访问日志access_log错误日志error_log
[[email protected] 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
[[email protected] httpd-2.2.31]# tail /usr/local/httpd/logs/error_log

 

以上是关于centos-6.5 安装apache的主要内容,如果未能解决你的问题,请参考以下文章

CentOS 6.5下源码安装LAMP(Linux+Apache+Mysql+Php)环境

CentOS 6.5 apache源码安装2.0版

CentOS 6.5下源码安装LAMP(Linux+Apache+Mysql+Php)环境

Centos 6.5编译安装LAMP

CentOS-6.5(X64)使用yum安装LAMP环境

CentOS 6.5 编译安装 LNMP环境