本文介绍,在CentOS 7下安装Apache HTTP Server。这里我们使用源码方式,进行安装
目标:将Apache httpd 2.4.16安装到CentOS 7主机的 /http-server 目录下
首先访问Apache HTTP Server官网,下载Apache httpd 2.4.16源码文件
我们将安装包存放在
/package-data-temp目录下
或者使用wget进行下载
# wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.16.tar.gz
解压下载下来的包
[root@bogon package-data-temp]# ls -a . .. httpd-2.4.16.tar.gz [root@bogon package-data-temp]# tar -xvf httpd-2.4.16.tar.gz
为了将Apache htpp server安装到 /http-server目录下,先到根目录下建立此目录
[root@bogon /]# mkdir http-server [root@bogon /]# ls -a . boot home lib64 opt root srv usr .. dev http-server media package-data-temp run sys var bin etc lib mnt proc sbin tmp
进入刚刚解压好的
# cd httpd-2.4.16/
检测安装环境
# ./configure --prefix=/http-server
下面是./configure 检测环境的输出提示
# ./configure --prefix=/http-server checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/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... no configure: error: APR not found. Please read the documentation.
根据提示的最后一句,可知Apache APR没有安装,查找官方手册后,得知,需要APR,并将apr和apr-util解压到httpd_source_tree_root/srclib,并且不能有版本号,httpd_source_tree_root指的是http server安装文件的源目录。
下面,我们直接进入
[root@bogon httpd-2.4.16]# cd srclib/ [root@bogon srclib]# pwd /package-data-temp/httpd-2.4.16/srclib [root@bogon srclib]# ls -a . .. Makefile.in
将下载下来的,或者使用wget下载文件到此目录下
# ls -a . .. apr-1.5.2.tar.gz apr-util-1.5.4.tar.gz Makefile.in
解压文件
# ls -a . .. apr-1.5.2 apr-1.5.2.tar.gz apr-util-1.5.4 apr-util-1.5.4.tar.gz Makefile.in
如果此时再次运行
# ./configure --prefix=/http-server
依然会输出
configure: error: APR not found. Please read the documentation.
的提示,我们前面说过了,apr和apr-util不能有版本号,所以我们需要修改文件夹名称,去掉版本号
# mv apr-1.5.2 apr # mv apr-util-1.5.4 apr-util
再次运行
# ./configure --prefix=/http-server
又有新的警告提示了
checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/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... reconfig configuring package in srclib/apr now 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 Configuring APR library Platform: x86_64-unknown-linux-gnu checking for working mkdir -p... yes APR Version: 1.5.2 checking for chosen layout... apr checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/package-data-temp/httpd-2.4.16/srclib/apr': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details configure failed for srclib/apr [root@bogon httpd-2.4.16]#
从提示可以看出,缺少C编译器。好吧,我们现在就安装C编译器
使用下面命令安装gcc
# yum install gcc
下面是安装详情
已安装: gcc.x86_64 0:4.8.3-9.el7 作为依赖被安装: cpp.x86_64 0:4.8.3-9.el7 glibc-devel.x86_64 0:2.17-78.el7 glibc-headers.x86_64 0:2.17-78.el7 kernel-headers.x86_64 0:3.10.0-229.7.2.el7 libmpc.x86_64 0:1.0.1-3.el7 完毕!
再次检查环境
# ./configure --prefix=/http-server
什么还是通不过?还有警告
checking for pcre-config... false configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
从提示,可以看出需要安装prce,并且给出了网址,那我们就去PCRE官网去看看,在PCRE下载目录,可以看到各个版本和格式的文件,到底下载那个呢?这里我们下载pcre-8.36.tar.gz,为什么不下载 因为提示上面,没有说pcre2 xxx, 事实也证明当前版本没有支持到pcre2.
那就继续下载,解压,安装
在这里对PCRE采用默认路径安装
[root@bogon pcre-8.36]# ./configure
在对pcre-8.36安装环境进行测试的时候,发现需要
... .... ...... checking for sys/stat.h... (cached) yes checking dirent.h usability... yes checking dirent.h presence... yes checking for dirent.h... yes checking windows.h usability... no checking windows.h presence... no checking for windows.h... no configure: error: You need a C++ compiler for C++ support.
需要使用如下命令解决
[root@bogon pcre-8.36]# yum install gcc-c++
已安装: gcc-c++.x86_64 0:4.8.3-9.el7 作为依赖被安装: libstdc++-devel.x86_64 0:4.8.3-9.el7 完毕!
再次检测pcre安装环境
[root@bogon pcre-8.36]# ./configure
pcre-8.36 configuration summary: Install prefix .................. : /usr/local C preprocessor .................. : gcc -E C compiler ...................... : gcc C++ preprocessor ................ : g++ -E C++ compiler .................... : g++ Linker .......................... : /usr/bin/ld -m elf_x86_64 C preprocessor flags ............ : C compiler flags ................ : -g -O2 -fvisibility=hidden C++ compiler flags .............. : -O2 -fvisibility=hidden -fvisibility-inlines-hidden Linker flags .................... : Extra libraries ................. : Build 8 bit pcre library ........ : yes Build 16 bit pcre library ....... : no Build 32 bit pcre library ....... : no Build C++ library ............... : yes Enable JIT compiling support .... : no Enable UTF-8/16/32 support ...... : no Unicode properties .............. : no Newline char/sequence ........... : lf \R matches only ANYCRLF ......... : no EBCDIC coding ................... : no EBCDIC code for NL .............. : n/a Rebuild char tables ............. : no Use stack recursion ............. : yes POSIX mem threshold ............. : 10 Internal link size .............. : 2 Nested parentheses limit ........ : 250 Match limit ..................... : 10000000 Match limit recursion ........... : MATCH_LIMIT Build shared libs ............... : yes Build static libs ............... : yes Use JIT in pcregrep ............. : no Buffer size for pcregrep ........ : 20480 Link pcregrep with libz ......... : no Link pcregrep with libbz2 ....... : no Link pcretest with libedit ...... : no Link pcretest with libreadline .. : no Valgrind support ................ : no Code coverage ................... : no
输出OK,使用make进行编译
[root@bogon pcre-8.36]# make
安装pcre
[root@bogon pcre-8.36]# make install
至此,我们解决了Apache HTTP Server安装过程中的PCRE依赖问题,即刚刚检测安装环境时的如下提示
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
再次检测Apache HTTP Server安安装环境
# ./configure --prefix=/http-server
这回检测总算OK了,可以对Apache HTTP Server 进行正式安装了
.... ...... .......... config.status: creating include/ap_config_layout.h config.status: creating support/apxs config.status: creating support/apachectl config.status: creating support/dbmmanage config.status: creating support/envvars-std config.status: creating support/log_server_status config.status: creating support/logresolve.pl config.status: creating support/phf_abuse_log.cgi config.status: creating support/split-logfile config.status: creating build/rules.mk config.status: creating build/pkg/pkginfo config.status: creating build/config_vars.sh config.status: creating include/ap_config_auto.h config.status: executing default commands
编译Apache HTTP Server 源文件
[root@bogon httpd-2.4.16]# make
.... ...... ........ http-server/modules -module -avoid-version mod_rewrite.lo make[4]: 离开目录“/package-data-temp/httpd-2.4.16/modules/mappers” make[3]: 离开目录“/package-data-temp/httpd-2.4.16/modules/mappers” make[2]: 离开目录“/package-data-temp/httpd-2.4.16/modules” make[2]: 进入目录“/package-data-temp/httpd-2.4.16/support” make[2]: 离开目录“/package-data-temp/httpd-2.4.16/support” make[1]: 离开目录“/package-data-temp/httpd-2.4.16”
安装Apache HTTP Server
[root@bogon httpd-2.4.16]# make install
Installing configuration files mkdir /http-server/conf mkdir /http-server/conf/extra mkdir /http-server/conf/original mkdir /http-server/conf/original/extra Installing HTML documents mkdir /http-server/htdocs Installing error documents mkdir /http-server/error Installing icons mkdir /http-server/icons mkdir /http-server/logs Installing CGIs mkdir /http-server/cgi-bin Installing header files Installing build system files Installing man pages and online manual mkdir /http-server/man mkdir /http-server/man/man1 mkdir /http-server/man/man8 mkdir /http-server/manual make[1]: 离开目录“/package-data-temp/httpd-2.4.16”
安装完成后,默认情况下,Apache HTTP Server是没有运行的
运行Apache HTTP Server
[root@bogon ~]# /http-server/bin/apachectl -k start AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 220.250.64.225. Set the 'ServerName' directive globally to suppress this message
上面的输入有额外信息,我们先不管,直接打开浏览器,在地址栏中输入
http://localhost/
对于以下的提示信息
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 220.250.64.225. Set the 'ServerName' directive globally to suppress this message
我们可以通过VIM编辑如下
[root@bogon ~]# vi /http-server/conf/httpd.conf
大约在188行左右,将
将
#ServerName www.example.com:80
修改为
ServerName localhost:80
保存后,重启httpd服务即可。
[root@bogon ~]# /http-server/bin/apachectl -k stop [root@bogon ~]# /http-server/bin/apachectl -k start
至此,我们用源码方式安装完了Apache HTTP Server。中间走了不少弯路,但一个基本思路是,Apache HTTP Server服务缺少什么组件,就去补充安装什么组件