一、参考链接

阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区 (aliyun.com)

apache镜像-apache下载地址-apache安装教程-阿里巴巴开源镜像站 (aliyun.com)

Apache(Web服务器软件)_百度百科 (baidu.com)

编译安装_Apache中文文档 (apachehttpd.com)

二、Apache 简介

Apache(音译为阿帕奇)是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。

下载地址:https://mirrors.aliyun.com/apache/

三、Apache编译安装(基于CentOS系统)

1、登录CentOS系统

image-20211222172652617

2、安装依赖包

编译安装Apache HTTP Server,目前最新的版本为2.4.52,将apr,apr-util,pcre等相关依赖包编译安装好即可。

若上述安装包已全部安装完成,可以直接进行Apache安装。

? apr安装

下载链接:https://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz

image-20211222173930229

  1. # 测试YUM源是否能够正常
  2. [root@centos apache]# yum clean all
  3. [root@centos apache]# yum repolist
  4. # 下载压缩包
  5. [root@centos apache]# wget https://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz
  6. # 查看apr-1.7.0.tar.gz
  7. [root@centos apache]# ll
  8. total 1072
  9. -rw-r--r-- 1 root root 1093896 Jul 6 2020 apr-1.7.0.tar.gz
  10. #解压压缩包
  11. [root@centos apache]# tar -zxvf apr-1.7.0.tar.gz
  12. [root@centos apache]# ll
  13. total 1076
  14. drwxr-xr-x 27 1001 1001 4096 Apr 2 2019 apr-1.7.0
  15. -rw-r--r-- 1 root root 1093896 Jul 6 2020 apr-1.7.0.tar.gz
  16. # 进入解压后的文件夹
  17. [root@centos apache]# cd apr-1.7.0
  18. # 创建apr安装目录文件夹
  19. [root@centos apr-1.7.0]# mkdir -p /usr/local/apr/apr
  20. # 安装配置
  21. [root@centos apr-1.7.0]# ./configure --prefix=/usr/local/apr/apr/
  22. # 编译
  23. [root@centos apr-1.7.0]# make
  24. #安装
  25. [root@centos apr-1.7.0]# make install

部分安装过程截图如下:

image-20211222181823740

image-20211222181944953

?apr-util安装

下载链接:https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz

image-20211222182358695

  1. [root@centos apache]# wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
  2. [root@centos apache]# ll
  3. total 1624
  4. drwxr-xr-x 28 1001 1001 4096 Dec 22 18:19 apr-1.7.0
  5. -rw-r--r-- 1 root root 1093896 Jul 6 2020 apr-1.7.0.tar.gz
  6. drwxr-xr-x 20 1001 1001 4096 Oct 18 2017 apr-util-1.6.1
  7. -rw-r--r-- 1 root root 554301 Jul 6 2020 apr-util-1.6.1.tar.gz
  8. [root@centos apache]#
  9. [root@centos apache]# cd apr-util-1.6.1
  10. [root@centos apr-util-1.6.1]#
  11. [root@centos apr-util-1.6.1]# mkdir /usr/local/apr/util
  12. # --with-apru命令的意思是指定自定义的apr的安装位置
  13. [root@centos apr-util-1.6.1]# ./configure --prefix=/usr/local/apr/util --with-apr=/usr/local/apr/apr
  14. # 编译
  15. [root@centos apr-util-1.6.1]# make
  16. #安装
  17. [root@centos apr-util-1.6.1]# make install

部分安装过程截图如下:

image-20211222183248687

?pcre安装

下载链接:https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz/download

  1. [root@centos apache]# ll
  2. total 3672
  3. drwxr-xr-x 28 1001 1001 4096 Dec 22 18:19 apr-1.7.0
  4. -rw-r--r-- 1 root root 1093896 Jul 6 2020 apr-1.7.0.tar.gz
  5. drwxr-xr-x 21 1001 1001 4096 Dec 22 18:32 apr-util-1.6.1
  6. -rw-r--r-- 1 root root 554301 Jul 6 2020 apr-util-1.6.1.tar.gz
  7. -rw-r--r-- 1 root root 2096552 Dec 22 18:39 pcre-8.45.tar.gz
  8. [root@centos apache]#
  9. [root@centos apache]# tar -zxvf pcre-8.45.tar.gz
  10. [root@centos apache]# cd pcre-8.45/
  11. [root@centos pcre-8.45]#mkdir /usr/local/pcre
  12. [root@centos pcre-8.45]# ./configure --prefix=/usr/local/pcre/
  13. [root@centos pcre-8.45]# make
  14. [root@centos pcre-8.45]# make install

部分安装过程截图如下:

image-20211222184233674

image-20211222184444729

3、Apache安装

下载链接:阿里云开源镜像站资源目录 (aliyun.com)

image-20211222172557369

  1. [root@centos ~]# wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.52.tar.gz
  2. [root@centos apache]# ll
  3. total 13188
  4. drwxr-xr-x 28 1001 1001 4096 Dec 22 18:19 apr-1.7.0
  5. -rw-r--r-- 1 root root 1093896 Jul 6 2020 apr-1.7.0.tar.gz
  6. drwxr-xr-x 21 1001 1001 4096 Dec 22 18:32 apr-util-1.6.1
  7. -rw-r--r-- 1 root root 554301 Jul 6 2020 apr-util-1.6.1.tar.gz
  8. drwxr-xr-x 12 504 games 4096 Dec 16 21:49 httpd-2.4.52
  9. -rw-r--r-- 1 root root 9719976 Dec 20 17:36 httpd-2.4.52.tar.gz
  10. drwxr-xr-x 9 1169 1169 12288 Dec 22 18:45 pcre-8.45
  11. -rw-r--r-- 1 root root 2096552 Dec 22 18:39 pcre-8.45.tar.gz
  12. [root@centos apache]# cd httpd-2.4.52
  13. [root@centos httpd-2.4.52]#
  14. [root@centos httpd-2.4.52]# mkdir /usr/local/httpd
  15. [root@centos httpd-2.4.52]# ./configure --prefix=/usr/local/httpd/
  16. checking for chosen layout... Apache
  17. checking for working mkdir -p... yes
  18. checking for grep that handles long lines and -e... /bin/grep
  19. checking for egrep... /bin/grep -E
  20. checking build system type... x86_64-pc-linux-gnu
  21. checking host system type... x86_64-pc-linux-gnu
  22. checking target system type... x86_64-pc-linux-gnu
  23. configure:
  24. configure: Configuring Apache Portable Runtime library...
  25. configure:
  26. checking for APR... no
  27. configure: error: APR not found. Please read the documentation.
  28. # 因修改了apr的默认安装位置,提示找不到apr,使用帮助命令查看。
  29. [root@centos httpd-2.4.52]# ./configure --help
  30. [root@centos httpd-2.4.52]# ./configure --help | grep -i apr
  31. --enable-hook-probes Enable APR hook probes
  32. --with-included-apr Use bundled copies of APR/APR-Util
  33. --with-apr=PATH prefix for installed APR or the full path to
  34. apr-config
  35. --with-apr-util=PATH prefix for installed APU or the full path to
  36. # 指定自定义的目录
  37. [root@centos httpd-2.4.52]# ./configure --prefix=/usr/local/httpd/ --with-apr=/usr/local/apr/apr/ --with-apr-util=/usr/
  38. local/apr/util/ --with-pcre=/usr/local/pcre/ --with-included-apr
  39. local/apr/util/ --with-pcre=/usr/local/pcre/
  40. # 编译
  41. [root@centos httpd-2.4.52]# make
  42. # 安装
  43. [root@centos httpd-2.4.52]# make install
  44. # 修改配置信息
  45. [root@centos httpd-2.4.52]# vim /usr/local/httpd/conf/httpd.conf
  46. ServerName localhost:80
  47. 保存退出
  48. # 启动Apache服务
  49. [root@centos ~]# /usr/local/httpd/bin/apachectl -k start
  50. [root@localhost ~]# /usr/local/httpd/bin/apachectl -T
  51. httpd (pid 66510) already running
  52. [root@localhost ~]#
  53. [root@localhost ~]# cd /usr/local/httpd/
  54. [root@localhost httpd]# ll
  55. total 44
  56. drwxr-xr-x 2 root root 302 Dec 22 19:35 bin
  57. drwxr-xr-x 2 root root 253 Dec 22 19:35 build
  58. drwxr-xr-x 2 root root 78 Dec 22 19:10 cgi-bin
  59. drwxr-xr-x 4 root root 84 Dec 22 19:47 conf
  60. drwxr-xr-x 3 root root 4096 Dec 22 19:10 error
  61. drwxr-xr-x 2 root root 24 Dec 22 19:10 htdocs
  62. drwxr-xr-x 3 root root 8192 Dec 22 19:10 icons
  63. drwxr-xr-x 2 root root 8192 Dec 22 19:35 include
  64. drwxr-xr-x 3 root root 281 Dec 22 19:35 lib
  65. drwxr-xr-x 2 root root 58 Dec 22 19:55 logs
  66. drwxr-xr-x 4 root root 30 Dec 22 19:10 man
  67. drwxr-xr-x 14 root root 8192 Dec 22 19:10 manual
  68. drwxr-xr-x 2 root root 4096 Dec 22 19:35 modules
  69. [root@localhost httpd]# cd htdocs/
  70. [root@localhost htdocs]# ll
  71. total 4
  72. -rw-r--r-- 1 504 games 45 Jun 12 2007 index.html
  73. [root@localhost htdocs]# cat index.html
  74. <html><body><h1>It works!</h1></body></html>
  75. [root@localhost htdocs]#

部分安装过程截图如下:

image-20211222173012236

image-20211222185751975

image-20211222191308274

image-20211222195555830

四、总结与反馈

在安装相应的依赖包的过程中,也会发生一些报错,也需要安装相应的组件,可以将报错信息复制粘贴至网上,搜索查看对应的解决办法。

这里也罗列了几个在安装过程中报错的信息,供大家参考。

报错信息1

  1. # 报错信息
  2. [root@centos apr-1.7.0]# ./configure --prefix=/usr/local/apr/apr/
  3. checking build system type... x86_64-pc-linux-gnu
  4. checking host system type... x86_64-pc-linux-gnu
  5. checking target system type... x86_64-pc-linux-gnu
  6. Configuring APR library
  7. Platform: x86_64-pc-linux-gnu
  8. checking for working mkdir -p... yes
  9. APR Version: 1.7.0
  10. checking for chosen layout... apr
  11. checking for gcc... no
  12. checking for cc... no
  13. checking for cl.exe... no
  14. configure: error: in `/root/apache/apr-1.7.0':
  15. configure: error: no acceptable C compiler found in $PATH
  16. See `config.log' for more details
  17. [root@centos apr-1.7.0]#
  18. [root@centos apr-1.7.0]# yum -y install gcc
  19. 参考链接:https://blog.csdn.net/weixin_33858249/article/details/91574176

报错信息2

  1. # 报错信息2
  2. [root@centos apr-util-1.6.1]# make
  3. make[1]: Entering directory `/root/apache/apr-util-1.6.1'
  4. /bin/sh /usr/local/apr/apr//build-1/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/root/apache/apr-util-1.6.1/include -I/root/apache/apr-util-1.6.1/include/private -I/usr/local/apr/apr//include/apr-1 -o xml/apr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
  5. xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
  6. #include <expat.h>
  7. ^
  8. compilation terminated.
  9. make[1]: *** [xml/apr_xml.lo] Error 1
  10. make[1]: Leaving directory `/root/apache/apr-util-1.6.1'
  11. make: *** [all-recursive] Error 1
  12. # 解决办法
  13. [root@centos apr-util-1.6.1]# yum install -y expat-devel
  14. 参考链接:https://blog.csdn.net/weixin_43930641/article/details/105269092

报错信息3

  1. checking for windows.h... no
  2. configure: error: Invalid C++ compiler or C++ compiler flags
  3. # yum install -y gcc-c++
  4. 参考链接:https://blog.csdn.net/weixin_43930641/article/details/105313937

更多相关文章

  1. React Native项目编译通不过, 出现 The "android" command is dep
  2. build android for VMware
  3. Android编译过程详解(二)
  4. Android增量编译3~5秒的背后
  5. Win10下mysql 8.0.15 安装配置图文教程
  6. win10家庭版64位下mysql 8.0.15 安装配置方法图文教程
  7. MYSQL本地安装以及出现的问题解决
  8. mysql 8.0.15 安装配置图文教程
  9. mysql 8.0.15 安装配置方法图文教程

随机推荐

  1. android VelocityTracker简单用法
  2. Android Layout xml 中的几个概念
  3. App自动更新之通知栏下载
  4. Android黑科技动态加载(二)之Android中的
  5. android 透明状态栏与沉浸式
  6. Kotlin 写 Android 单元测试(三),Mockito mo
  7. Android 学习
  8. Google Maps Android API v2初体验
  9. 深入理解 Android消息处理系统的原理
  10. [置顶] 【Android】 基于XMPP Smack框架