1.1 安装Apache2.4
1.1.1 安装前准备
卸载系统默认安装的Apache
一般来说,操作系统自带或者Apache rpm包方式安装的Apache版本都比较低,且更新不及时,因此我们需要卸载掉安装操作系统时默认被安装上的Apache软件。
查询当前系统中已安装的Apache软件包通过rpm -qa httpd*命令,我们可以查询当前系统中已安装的Apache软件包,具体查询操作如下:
#查询[root@localhost /]# rpm -qa httpd*httpd-tools-2.2.15-69.el6.centos.x86_64httpd-2.2.15-69.el6.centos.x86_64#卸载[root@localhost /]# rpm -e --nodeps httpd-2.2.15-69.el6.centos.x86_64[root@localhost /]# rpm -qa httpd[root@localhost /]
Rpm 命令参数说明:
-e 等同于erase表示移除的意思
---nodeps 意思是不考虑依赖
1.1.2 安装依赖包
1)yum安装依赖包
提示:必须先用yum把需要的依赖包安装好,再源码编译安装其他的依赖包和Apache软件包,如果先源码编译安装apr,apr-util,再yum安装其他依赖包,最后编译安装Apache时容易安装失败。(经验所得)
[root@apache httpd-2.4.37]# yum -y install gcc gcc-c++ zlib-devel openssl-devel expat-deve pcre pcre-devel
2) 源码安装apr依赖包
下载apr依赖软件包:
[root@apache /]# mkdir -p /home/oldboy/tools[root@apache /]# cd /home/oldboy/tools/[root@apache tools]# wget http://mirrors.hust.edu.cn/apache/apr/apr-1.6.5.tar.gz--2018-12-06 10:06:22-- http://mirrors.hust.edu.cn/apache/apr/apr-1.6.5.tar.gzResolving mirrors.hust.edu.cn... 202.114.18.160Connecting to mirrors.hust.edu.cn|202.114.18.160|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 1073556 (1.0M) [application/octet-stream]Saving to: “apr-1.6.5.tar.gz” 100%[=====================================================>] 1,073,556 89.7K/s in 12s 2018-12-06 10:06:36 (85.1 KB/s) - “apr-1.6.5.tar.gz” saved [1073556/1073556] [root@apache tools]# wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.gz--2018-12-06 10:06:57-- http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.gzResolving mirrors.hust.edu.cn... 202.114.18.160Connecting to mirrors.hust.edu.cn|202.114.18.160|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 554301 (541K) [application/octet-stream]Saving to: “apr-util-1.6.1.tar.gz” 100%[=====================================================>] 554,301 112K/s in 4.8s 2018-12-06 10:07:02 (112 KB/s) - “apr-util-1.6.1.tar.gz” saved [554301/554301] [root@apache tools]# lltotal 10560-rw-r--r--. 1 root root 1073556 Sep 14 12:07 apr-1.6.5.tar.gz-rw-r--r--. 1 root root 554301 Oct 23 2017 apr-util-1.6.1.tar.gz
安装apr:
[root@apache tools]# tar zxf apr-1.6.5.tar.gz [root@apache tools]# tar zxf apr-util-1.6.1.tar.gz [root@apache tools]# cd apr-1.6.5[root@apache apr-1.6.5]# mkdir /usr/local/apr-1.6.5[root@apache apr-1.6.5]# ./configure --prefix=/usr/local/apr-1.6.5…………省略内容…………[root@apache apr-1.6.5]# make && make install…………省略内容…………[root@apache apr-1.6.5]# ls /usr/local/apr-1.6.5/bin build-1 include lib[root@apache apr-1.6.5]# cd ../apr-util-1.6.1[root@apache apr-util-1.6.1]# mkdir /usr/local/apr-util-1.6.1[root@apache apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util-1.6.1/ --with-apr=/usr/local/apr-1.6.5/…………省略内容…………[root@apache apr-util-1.6.1]# make && make install…………省略内容………[root@apache apr-util-1.6.1]# ls /usr/local/apr-util-1.6.1/bin include lib
1.1.3 安装Apache
1)下载httpd-2.4.37
[root@apache tools]# wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.37.tar.gz--2018-12-06 10:02:03-- http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.37.tar.gzResolving mirrors.hust.edu.cn... 202.114.18.160Connecting to mirrors.hust.edu.cn|202.114.18.160|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 9177278 (8.8M) [application/octet-stream]Saving to: “httpd-2.4.37.tar.gz” 100%[=====================================================>] 9,177,278 221K/s in 67s 2018-12-06 10:03:12 (133 KB/s) - “httpd-2.4.37.tar.gz” saved [9177278/9177278]
2)编译安装
[root@apache httpd-2.4.37]# ./configure --prefix=/opt/httpd-2.4.37 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr-1.6.5/ --with-apr-util=/usr/local/apr-util-1.6.1/ --enable-modules=most --enable-mpms-shared=all --with-mpm-prefork…………省略部分内容………… Server Version: 2.4.37 Install prefix: /opt/httpd-2.4.37 C compiler: gcc -std=gnu99 CFLAGS: -g -O2 -pthread CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE LDFLAGS: LIBS: C preprocessor: gcc -E[root@apache httpd-2.4.37]# make && make install…………省略部分内容…………mkdir /opt/httpd-2.4.37/manualmake[1]: Leaving directory `/home/oldboy/tools/httpd-2.4.37'[root@apache httpd-2.4.37]# ls /opt/httpd-2.4.37/bin build cgi-bin conf error htdocs icons include logs man manual modules[root@apache httpd-2.4.37]# ln -s /opt/httpd-2.4.37/ /opt/httpd[root@apache httpd-2.4.37]# ll -d /opt/httpdlrwxrwxrwx. 1 root root 18 Dec 6 12:04 /opt/httpd -> /opt/httpd-2.4.37/
1.1.4 启动Apache服务
1)检查语法
[root@apache /]# /opt/httpd/bin/apachectl -tAH00557: httpd: apr_sockaddr_info_get() failed for apacheAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this messageSyntax OK
2)启动Apache服务
[root@apache /]# /opt/httpd/bin/apachectl startAH00557: httpd: apr_sockaddr_info_get() failed for apacheAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
3)检查httpd端口
[root@apache /]# lsof -i :80COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEhttpd 108776 root 4u IPv6 157608 0t0 TCP *:http (LISTEN)httpd 108777 daemon 4u IPv6 157608 0t0 TCP *:http (LISTEN)httpd 108778 daemon 4u IPv6 157608 0t0 TCP *:http (LISTEN)httpd 108779 daemon 4u IPv6 157608 0t0 TCP *:http (LISTEN)[root@apache /]# ps -ef|grep httpdroot 108776 1 0 12:07 ? 00:00:00 /opt/httpd-2.4.37/bin/httpd -k startdaemon 108777 108776 0 12:07 ? 00:00:00 /opt/httpd-2.4.37/bin/httpd -k startdaemon 108778 108776 0 12:07 ? 00:00:00 /opt/httpd-2.4.37/bin/httpd -k startdaemon 108779 108776 0 12:07 ? 00:00:00 /opt/httpd-2.4.37/bin/httpd -k startroot 108863 37886 0 12:08 pts/0 00:00:00 grep httpd
4)Windows访问Apache服务
查看IP地址
[root@apache /]# ifconfig eth0eth0 Link encap:Ethernet HWaddr 00:0C:29:A9:47:CC inet addr:10.90.3.130 Bcast:10.90.3.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fea9:47cc/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2792510 errors:0 dropped:0 overruns:0 frame:0 TX packets:73729 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:481330391 (459.0 MiB) TX bytes:8763678 (8.3 MiB)
安装Apache2.4到此结束!