安装Apache(httpd)

安装Apache

apr和apr-util是一个通用函数库,他能让httpd不去关心底层的操作系统平台,可以很方便的移植(linux到Windows)

源码包安装httpd(2.4.29):

httpd源码包
apr包
apr-util包

下载包到/usr/local/src/下:

[root@shuai-01 src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz
[root@shuai-01 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
[root@shuai-01 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2
[root@shuai-01 src]# ls              httpd-2.2.34.tar.gz
apr-1.6.3.tar.gz        httpd-2.4.29.tar.gz
apr-util-1.6.1.tar.bz2  mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
httpd-2.2.34            mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz

解压软件包:

[root@shuai-01 src]# tar zxvf apr-1.6.3.tar.gz
[root@shuai-01 src]# tar jxvf apr-util-1.6.1.tar.bz2
[root@shuai-01 src]# tar zxvf  httpd-2.4.29.tar.gz
[root@shuai-01 src]# ls
apr-1.6.3               httpd-2.2.34.tar.gz
apr-1.6.3.tar.gz        httpd-2.4.29
apr-util-1.6.1          httpd-2.4.29.tar.gz
apr-util-1.6.1.tar.bz2  mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
httpd-2.2.34            mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz

编译安装(apr):

进入apr文件里,configure , make ,make install,每一步完成后检查是否成功。

[root@shuai-01 src]# cd apr-1.6.3/
[root@shuai-01 apr-1.6.3]# 
[root@shuai-01 apr-1.6.3]# ./configure --prefix=/usr/local/apr

[root@shuai-01 apr-1.6.3]# echo $?
0
[root@shuai-01 apr-1.6.3]# make
[root@shuai-01 apr-1.6.3]# echo $?
0
[root@shuai-01 apr-1.6.3]# make install
[root@shuai-01 apr-1.6.3]# echo $?
0

安装apr-util:

进入目录:

[root@shuai-01 apr-1.6.3]# cd ../apr-util-1.6.1
[root@shuai-01 apr-util-1.6.1]# 

编译安装apr-util

[root@shuai-01 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@shuai-01 apr-util-1.6.1]# make
[root@shuai-01 apr-util-1.6.1]# echo $?
0
[root@shuai-01 apr-util-1.6.1]# make install

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

解决:缺少expat-devel包

    yum install expat-devel

安装httpd:

进入httpd-2.4.29目录下

[root@shuai-01 src]# cd httpd-2.4.29/
[root@shuai-01 httpd-2.4.29]# 
[root@shuai-01 httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@shuai-01 apr-util-1.6.1]# make
[root@shuai-01 apr-util-1.6.1]# echo $?
0
[root@shuai-01 apr-util-1.6.1]# make install

[root@shuai-01 apache2.4]# ls
bin    cgi-bin  error   icons    lib   man     modules
build  conf     htdocs  include  logs  manual

bin 可执行文件存放目录 (bin/httpd 起动文件的目录)
conf 配置文件所在目录
htdocs 存放访问页面(默认网站)
logs 日志相关的目录(错误日志,访问日志)
modules 存放模块

查看Apache加载那些模块

[root@shuai-01 apache2.4]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::4f59:7251:18f1:8716. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_event_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)

启动Apache

[root@shuai-01 apache2.4]# /usr/local/apache2.4/bin/apachectl start

[root@shuai-01 apache2.4]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1505/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2239/master         
tcp6       0      0 :::80                   :::*                    LISTEN      64263/httpd         
tcp6       0      0 :::22                   :::*                    LISTEN      1505/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2239/master  

httpd默认监听80端口,
sshd默认监听22端口
mysqld默认监听3306端口
25端口是发邮件的

问题2:checking for APR-util… configure: error: the –with-apr-util parameter is incorrect

[root@getlnx05 httpd-2.4.6]#  ./configure --prefix=/usr/local/apache  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

checking for chosen layout... Apache

checking for working mkdir -p... yes

checking for grep that handles long lines and -e... /bin/grep

checking for egrep... /bin/grep -E

checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking target system type... x86_64-unknown-linux-gnu

configure:

configure: Configuring Apache Portable Runtime library...

configure:

checking for APR... yes

  setting CC to "gcc"

  setting CPP to "gcc -E"

  setting CFLAGS to " -g -O2 -pthread"

  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"

  setting LDFLAGS to " "

configure:

configure: Configuring Apache Portable Runtime Utility library...

configure:

checking for APR-util... configure: error: the --with-apr-util parameter is incorrect. It must specify an install prefix, a build directory, or an apu-config file.

[root@getlnx05 httpd-2.4.6]#

一般是由于APR-util没有安装成功,可以通过验证该目录是否为空来判断,因为你有时候执行了make,忘了执行make isntall命令有可能导致这个错误。

[root@getlnx05 apr]# cd /usr/local/apr-util

[root@getlnx05 apr-util]# ls

问题三:configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

没有pcre包,
查找包

[root@shuai-01 httpd-2.4.29]# yum list |grep pcre

一般的lib库,通常带有lib , devel后缀。

安装包:

[root@shuai-01 httpd-2.4.29]# yum install -y pcre-devel

问题4:

./configure没有报错,执行make时报错,如下:

make[2]: * [exports.lo] Error 1

make[2]: Leaving directory `/usr/local/src/httpd-2.4.7/server’

make[1]: * [all-recursive] Error 1

make[1]: Leaving directory `/usr/local/src/httpd-2.4.7/server’

make: * [all-recursive] Error 1

之前apr,apr-util都编译安装成功。
编译参数:

./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util  --enable-so --enable-mods-shared=most

解决方案:
先退出编译安装:

make clean

在./configure 参数后面加上 ‘–with-included-apr’参数,再次进行编译

[root@shuai-01 httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-included-apr --enable-so --enable-mods-shared=most 

这时又出现另一个报错。错误如下:

configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

然后将apr包和apr-util包拷贝到/usr/local/src/httpd-2.4.29/srclib/目录下:

[root@shuai-01 httpd-2.4.29]# cp -r apr-1.6.3 /usr/local/src/httpd-2.4.29/srclib/apr
[root@shuai-01 httpd-2.4.29]# cp -r apr-util-1.6.1 /usr/local/src/httpd-2.4.29/srclib/apr-util

重新执行编译命令

[root@shuai-01 httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-included-apr --enable-so --enable-mods-shared=most 

编译完成,接着make也成功。

问题5:

1.so: undefined reference to `XML_ParserFree'
/opt/apache/httpd-2.4.26/srclib/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
/opt/apache/httpd-2.4.26/srclib/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
/opt/apache/httpd-2.4.26/srclib/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'
/opt/apache/httpd-2.4.26/srclib/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'
collect2: ld returned 1 exit status
make[2]: *** [htpasswd] Error 1
make[2]: Leaving directory `/opt/apache/httpd-2.4.26/support'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/opt/apache/httpd-2.4.26/support'
make: *** [all-recursive] Error 1

这里写图片描述

这个是所用的各个软件的版本,apr-1.6.3,apr-util-1.6.1
apr-util 1.6.0以上的版本
不再捆绑安装 expat ,但又需要 expat 的支持,所以我们得手动先安装 expat。

解决:

[root@shuailinux-01 httpd-2.4.34]# wget https://sourceforge.net/projects/expat/files/expat/2.2.3/expat-2.2.3.tar.bz2
[root@shuailinux-01 httpd-2.4.34]# tar xjvf expat-2.2.3.tar.bz2 
[root@shuailinux-01 httpd-2.4.34]# cd expat-2.2.3/
[root@shuailinux-01 httpd-2.4.34]# ./configure --prefix=/usr/local/expat
[root@shuai-01 expat-2.2.3]# make
[root@shuai-01 expat-2.2.3]# make install

再对apr-util重新编译安装
[root@shuailinux-01 httpd-2.4.34]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-expat=/usr/local/expat
[root@shuailinux-01 httpd-2.4.34]# make && make install

完成后,重新编译安装httpd

[root@shuailinux-01 httpd-2.4.34]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@shuailinux-01 httpd-2.4.34]# make && make install

搞定

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值