CentOS 7 安装Apache 2.4.39

使用源码在CentOS 7下安装 apache 2.4.39,之前趟了一遍,简单做个笔记。

STEP 1 安装apr

STEP 1.1 检查是否安装apr

[root@study ~]# yum list apr
# 如果没有安装, 则进入STEP 1.2;
# 查看apr的位置
[root@study ~]# whereis apr
apr: /usr/local/apr

STEP 1.2 安装apr

[root@study ~]# cd source
[root@study source]# wget http://DOWNLOAD/apr-1.7.0.tar.gz
# DOWNLOAD 替换相应的镜像
[root@study source]# tar -xzvf apr-1.7.0.tar.gz
[root@study source]# cd apr-1.7.0
[root@study apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@study apr-1.7.0]# make && make install 

 

STEP 2 安装libxml2

由于apahce 依赖的apr-util.1.6.1依赖libxml2库,如果没有安装libxml2库,则在apache的配置中会有如下错误产生:

usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserFree'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetUserData'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] 错误 1
make[2]: 离开目录“/opt/source/apache.httpd/httpd-2.4.39/support”
make[1]: *** [all-recursive] 错误 1
make[1]: 离开目录“/opt/source/apache.httpd/httpd-2.4.39/support”
make: *** [all-recursive] 错误 1

STEP 2.1 检查是否安装 libxml2

[root@study ~]# yum list libxml2
# 如果没有安装则,进行libxml2安装
[root@study ~]# yum install libxml2-devel

STEP 3 安装expat

如果没有安装expat,可能在安装apr-util中会报如下错误:

xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录
#include <expat.h>

STEP 3.1 检查是否安装expat

[root@study ~]# yum list expat
# 如果没有安装则进行安装
[root@study ~]# yum install expat-devel

STEP 4 安装apr-util

STEP 4.1 检查是否安装apr-util

[root@study ~]# yum list apr-util
# 如果没有安装则进入 STEP 4.2 进行安装
[root@study ~]# whereis apr-util
apr-util: /usr/local/apr-util

STEP 4.2 安装apr-util

[root@study ~]# cd source
[root@study source]# wget http://DOWNLOAD/apr-util-1.6.1.tar.gz
[root@study source]# tar -xzvf apr-util-1.6.1.tar.gz
[root@study source]# cd apr-util.1.6.1
[root@study apr-util.1.6.1]# ./configure --prefix=/usr/local/apr-util
[root@study aapr-util.1.6.1]# make && make install 

STEP 5 安装pcre

STEP 5.1 检查是否安装pcre

[root@study ~]# yum list pcre
# 如果没有安装,则进入 STEP 5.2 进行安装
[root@study ~]# whereis pcre
pcre: /usr/include/pcre.h /usr/local/pcre /usr/share/man/man3/pcre.3.gz

STEP 5.2 安装pcre

[root@study ~]# cd source
[root@study ~]# url=https://jaist.dl.sourceforge.net/project/pcre/pcre/8.43/pcre-8.43.tar.gz
[root@study source]# wget ${url}
[root@study source]# tar -xzvf pcre-8.43.tar.gz
[root@study source]# cd pcre-8.43
[root@study pcre-8.43]# ./configure --prefix=/usr/local/pcre
[root@study pcre-8.43]# make && make install

STEP 6 安装apache

[root@study source]# tar -xzvf http-2.4.39.tar.gz
[root@study source]# cd httpd-2.4.39
[root@study httpd-2.4.39]# ./configure --prefix=/usr/local/apache24 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
[root@study httpd-2.4.39]# make && make install

STEP 7 设置service文件

[root@study ~]# cd /usr/lib/systemd/system
[root@study system]# vim httpd.service

[Unit]
Description=Apache 2.4.39
After=network.target
After=syslog.target
[Service]
Type=forking
ExecStart=/usr/local/apache24/bin/apachectl -k start
ExecStop=/usr/local/apache24/bin/apachectl -k stop
ExecReload=/usr/local/apache24/bin/apachectl -k restart
[Install]
WantedBy=multi-user.target
Alias=http.service

STEP 8 设置防火墙以及开机启动

# 允许开放http服务
[root@study ~]# firewall-cmd --permanent --add-service=http 
# 打开http服务的80 tcp端口
[root@study ~]# firewall-cmd --permanent --add-port=80/tcp
# 重新加载防火墙规则
[root@study ~]# firewall-cmd --reload 
# 重新启动apach
[root@study ~]# systemctl restart httpd.service
# 设置开机启动
[root@study ~]# systemctl enable httpd.service

 

posted @ 2019-04-14 15:10  茄菲兔  阅读(3401)  评论(0编辑  收藏  举报