Linux rhel  6.4 编译安装apache过程(1)


注:以下摘取的都是安装过程中执行的命令,命令反馈没有贴出来以"......"代替。观看的时候注意执行命令时所在的目录。


安装平台

[root@chengmanyu ~]# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 6.4 (Santiago)


需要的工具版本以及下载地址

1.httpd-2.4.25.tar.gz 

(http://httpd.apache.org/download.cgi#apache24)

2.apr-1.5.2.tar.gz

(http://apr.apache.org/download.cgi)

3.apr-util-1.5.4.tar.gz

(http://apr.apache.org/download.cgi)

4.pcre-8.40.tar.gz 

(https://ftp.pcre.org/pub/pcre/)


下载好以后将这些工具上传到Linux的/media目录下。(我上传使用了winSCP工具)


解压缩

[root@chengmanyu media]# cd /media/

[root@chengmanyu media]# tar zxvf apr-1.5.2.tar.gz -C /opt/

......

[root@chengmanyu media]# tar zxvf apr-util-1.5.4\ .tar.gz -C /opt/

......

[root@chengmanyu media]# tar zxvf pcre-8.40.tar.gz -C /opt/

......

[root@chengmanyu media]# tar zxvf httpd-2.4.25.tar.gz -C /opt/

......


解压好后进入/opt目录,查看一下解压的结果

[root@chengmanyu media]# cd /opt/

[root@chengmanyu opt]# ls

apr-1.5.2  apr-util-1.5.4  httpd-2.4.25  pcre-8.40  rh


检查一下是否有Linux自带的httpd服务,如果有需要关闭相关的服务并用rpm卸载httpd相关的包。

[root@chengmanyu opt]# rpm -qa | grep httpd

[root@chengmanyu opt]#

我这里并之前并没有安装httpd相关的包。


安装httpd还需要gcc-c++

[root@chengmanyu opt]# yum -y install gcc-c++*

......


安装apr apr-util以及pcre三个工具,如果不安装这三个工具编译httpd的时候会报错,提示需要这三个工具。

安装apr

[root@chengmanyu opt]# cd apr-1.5.2/

[root@chengmanyu apr-1.5.2]# ls

......

[root@chengmanyu apr-1.5.2]# ./configure --prefix=/usr/local/apr

......

[root@chengmanyu apr-1.5.2]# make

......

[root@chengmanyu apr-1.5.2]# make install

......

继续安装apr-util

[root@chengmanyu apr-1.5.2]# cd /opt/apr-util-1.5.4/

[root@chengmanyu apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config

......

[root@chengmanyu apr-util-1.5.4]# make

......

[root@chengmanyu apr-util-1.5.4]# make install

......

继续安装pcre

[root@chengmanyu apr-util-1.5.4]# cd /opt/pcre-8.40/

[root@chengmanyu pcre-8.40]# ./configure --prefix=/usr/local/pcre

......

[root@chengmanyu pcre-8.40]# make

......

[root@chengmanyu pcre-8.40]# make install

......


这三个工具编译安装好后就可以继续httpd的安装了

[root@chengmanyu httpd-2.4.25]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/

(安装httpd并给出三个工具的路径)

......

[root@chengmanyu httpd-2.4.25]# make

......

[root@chengmanyu httpd-2.4.25]# make install

......


编译结束后如果没有报error的话,安装基本就结束了。

尝试下启动apache

启动:

[root@chengmanyu httpd-2.4.25]# /usr/local/apache/bin/apachectl start

AH00557: httpd: apr_sockaddr_info_get() failed for chengmanyu.test

AH00558: 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

(上面的问题并不影响使用,在接下来的配置中我们设置一下主机名就可以避免这个提示)


如果没有什么报错,那么apache已经开始运行了,我们检测一下我们的劳动成果。

先关掉本机的防火墙

[root@chengmanyu httpd-2.4.25]# service iptables stop

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Setting chains to policy ACCEPT: filter          [  OK  ]

iptables: Unloading modules:                               [  OK  ]


然后用在同一个域中的其他主机或在本机的浏览器中输入apache所在主机的 ip:80(ip+:80),浏览器跳转页面显示

it works!

到这里apache的安装已经完成了,但是现网中这样并不能直接使用还需要一些简单的设置。