1. 下载并安装apache软件
2.2下载链接:http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.34.tar.gz
2.4下载链接:http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.28.tar.gz
[root@dancheng_linux tools]# wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.34.tar.gz
--2017-12-18 08:06:53-- http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.34.tar.gz
Resolving mirrors.hust.edu.cn (mirrors.hust.edu.cn)... 202.114.18.160, 202.114.18.160
Connecting to mirrors.hust.edu.cn (mirrors.hust.edu.cn)|202.114.18.160|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7684419 (7.3M) [application/octet-stream]
Saving to: 鈎ttpd-2.2.34.tar.gz?
100%[=============================================================>] 7,684,419 150KB/s in 36s
2017-12-18 08:07:32 (206 KB/s) - 鈎ttpd-2.2.34.tar.gz?saved [7684419/7684419]
[root@dancheng_linux tools]# ls httpd-2.2.34.tar.gz
httpd-2.2.34.tar.gz
[root@dancheng_linux tools]# ls httpd-2.2.34.tar.gz -l
-rw-r--r--. 1 root root 7684419 Jul 10 09:29 httpd-2.2.34.tar.gz
[root@dancheng_linux tools]# ls httpd-2.2.34.tar.gz -sh
7.4M httpd-2.2.34.tar.gz
[root@dancheng_linux tools]# tar xf httpd-2.2.34.tar.gz
[root@dancheng_linux tools]# ls
httpd-2.2.34 httpd-2.2.34.tar.gz
[root@dancheng_linux tools]# cd httpd-2.2.34/
[root@dancheng_linux httpd-2.2.34]#
[root@dancheng_linux httpd-2.2.34]# ./configure \
> --prefix=/application/apache2.2.34 \
> --enable-deflate \
> --enable-expires \
> --enable-headers \
> --enable-modules=most \
> --enable-so \
> --with-mpm=worker \
> --enable-rewrite
在安装这个的时候遇到一个错误:错误提示是缺一个包
yum install zlib zlib-devel -y
[root@dancheng_linux httpd-2.2.34]# make
[root@dancheng_linux httpd-2.2.34]# make install
[root@dancheng_linux httpd-2.2.34]# rm -rf /application/apache
[root@dancheng_linux httpd-2.2.34]# ln -s /application/apache2.2.34/ /application/apache
2. 启动apache
先检查语法:
[root@dancheng_linux httpd-2.2.34]# /application/apache/bin/apachectl -t
开启服务:
[root@dancheng_linux httpd-2.2.34]# /application/apache/bin/apachectl start
查看端口占用:
[root@dancheng_linux httpd-2.2.34]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 56867 root 4u IPv6 101632 0t0 TCP *:http (LISTEN)
httpd 56874 daemon 4u IPv6 101632 0t0 TCP *:http (LISTEN)
httpd 56875 daemon 4u IPv6 101632 0t0 TCP *:http (LISTEN)
httpd 56876 daemon 4u IPv6 101632 0t0 TCP *:http (LISTEN)
查看httpd进程:
[root@dancheng_linux httpd-2.2.34]# ps -ef|grep httpd
root 56867 1 0 08:56 ? 00:00:00 /application/apache2.2.34/bin/httpd -k start
daemon 56873 56867 0 08:56 ? 00:00:00 /application/apache2.2.34/bin/httpd -k start
daemon 56874 56867 0 08:56 ? 00:00:00 /application/apache2.2.34/bin/httpd -k start
daemon 56875 56867 0 08:56 ? 00:00:00 /application/apache2.2.34/bin/httpd -k start
daemon 56876 56867 0 08:56 ? 00:00:00 /application/apache2.2.34/bin/httpd -k start
root 56965 4550 0 08:57 pts/0 00:00:00 grep --color=auto httpd
开启后在外面就可以访问到了:
如果配置完开启后,访问不到则依次检查:
1. iptables防火墙和selinux是否关闭
[root@dancheng_linux httpd-2.2.34]# /etc/init.d/iptables stop
这是关闭防火墙的命令,如果是生产环境允许80端口的访问,而不是关闭防火墙
关闭selinux:
临时方法:
[root@dancheng_linux httpd-2.2.34]# setenforce 0
永久方法:
[root@dancheng_linux httpd-2.2.34]# cat /etc/selinux/config |grep SELINUX=disabled
2. 通过下面命令确定httpd端口是否存在:
[root@dancheng_linux httpd-2.2.34]# netstat -lnt|grep 80
3. 查看是否有http进程存在
[root@dancheng_linux httpd-2.2.34]# ps -ef|grep http
4. 在服务器本地wget http://本地ip地址 测试
5. 在服务器本地curl http://本地ip地址 测试
[root@dancheng_linux httpd-2.2.34]# /application/apache/bin/apachectl -l
查看开启的模块
[root@dancheng_linux httpd-2.2.34]# /application/apache/bin/apachectl -l|egrep "_so|_rewrite|header|exp
ire|deflate"
mod_deflate.c
mod_expires.c
mod_headers.c
mod_rewrite.c
mod_so.c
重启Apache
apache/bin/apachectl graceful