博客列表 >apache编译安装

apache编译安装

哈
原创
2022年07月18日 11:06:19767浏览

镜像下载、域名解析、时间同步请点击 阿里云开源镜像站

源码包编译实例

下面通过编译安装httpd来深入理解源码包安装(httpd-2.4.54)

下载编译工具,httpd以及其两个依赖包的源码包

//源码包建议到官方网站下载

  1. [root@lnh ~]# mkdir xbz
  2. [root@lnh ~]# cd xbz/
  3. [root@lnh xbz]# dnf -y install gcc gcc-c++ make wget
  4. [root@lnh xbz]# wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.54.tar.gz
  5. [root@lnh xbz]# wget https://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz
  6. [root@lnh xbz]# wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
  7. [root@lnh xbz]# ls
  8. apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz

安装apr

  1. [root@lnh xbz]# ls
  2. apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz
  3. [root@lnh xbz]# tar -xf apr-1.7.0.tar.gz
  4. [root@lnh xbz]# ls
  5. apr-1.7.0 apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz
  6. //将apr解压到当前目录
  7. [root@lnh xbz]# cd apr-1.7.0/
  8. [root@lnh apr-1.7.0]# ls
  9. apr-config.in build-outputs.mk helpers misc strings
  10. apr.dep CHANGES include mmap support
  11. apr.dsp CMakeLists.txt libapr.dep network_io tables
  12. apr.dsw config.layout libapr.dsp NOTICE test
  13. apr.mak configure libapr.mak NWGNUmakefile threadproc
  14. apr.pc.in configure.in libapr.rc passwd time
  15. apr.spec docs LICENSE poll tools
  16. atomic dso locks random user
  17. build emacs-mode Makefile.in README
  18. build.conf encoding Makefile.win README.cmake
  19. buildconf file_io memory shmem
  20. //进入这个源码包可以看见里面被解压出来的东西
  21. [root@lnh apr-1.7.0]# ./configure --prefix=/usr/local/src/apr
  22. ...
  23. configure: creating ./config.status
  24. config.status: creating Makefile
  25. config.status: creating include/apr.h
  26. config.status: creating build/apr_rules.mk
  27. config.status: creating build/pkg/pkginfo
  28. config.status: creating apr-1-config
  29. config.status: creating apr.pc
  30. config.status: creating test/Makefile
  31. config.status: creating test/internal/Makefile
  32. config.status: creating include/arch/unix/apr_private.h
  33. config.status: executing libtool commands
  34. rm: cannot remove 'libtoolT': No such file or directory
  35. config.status: executing default commands
  36. //生成Makefile
  37. 一般常用的有 --prefix=PREFIX 这个选项的意思是定义软件包安装到哪
  38. 建议,源码包都是安装在/opt/目录下或者/usr/local/src目录下面
  39. [root@lnh apr-1.7.0]# make
  40. ...
  41. gcc -E -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I./include -I/root/xbz/apr-1.7.0/include/arch/unix -I./include/arch/unix -I/root/xbz/apr-1.7.0/include/arch/unix -I/root/xbz/apr-1.7.0/include -I/root/xbz/apr-1.7.0/include/private -I/root/xbz/apr-1.7.0/include/private export_vars.c | sed -e 's/^\#[^!]*//' | sed -e '/^$/d' >> apr.exp
  42. sed 's,^\(location=\).*$,\1installed,' < apr-1-config > apr-config.out
  43. sed -e 's,^\(apr_build.*=\).*$,\1/usr/local/src/apr/build-1,' -e 's,^\(top_build.*=\).*$,\1/usr/local/src/apr/build-1,' < build/apr_rules.mk > build/apr_rules.out
  44. make[1]: Leaving directory '/root/xbz/apr-1.7.0'
  45. //编译生成Makefile,此处虽然出现了make[1]: Leaving directory '/root/xbz/apr-1.7.0',但是没关系可以继续进行下一步安装
  46. [root@lnh apr-1.7.0]# make install
  47. ...
  48. /usr/bin/install -c -m 755 /root/xbz/apr-1.7.0/build/mkdir.sh /usr/local/src/apr/build-1
  49. for f in make_exports.awk make_var_export.awk; do \
  50. /usr/bin/install -c -m 644 /root/xbz/apr-1.7.0/build/${f} /usr/local/src/apr/build-1; \
  51. done
  52. /usr/bin/install -c -m 644 build/apr_rules.out /usr/local/src/apr/build-1/apr_rules.mk
  53. /usr/bin/install -c -m 755 apr-config.out /usr/local/src/apr/bin/apr-1-config
  54. //进行安装
  55. [root@lnh apr-1.7.0]# cd /usr/local/src/apr/
  56. [root@lnh apr]# ls
  57. bin build-1 include lib
  58. //进入apr的路径进行查看,默认情况下,系统搜索库文件的路径只有/lib,/usr/lib,我们需要进行修改在/etc/ld.so.conf.d/中创建以.conf为后缀名的文件,而后把要增添的路径直接写至此文件中。此时库文件增添的搜索路径重启后有效,若要使用增添的路径立即生效则要使用ldconfig命令
  59. [root@lnh apr]# cd /etc/ld.so.conf.d/
  60. [root@lnh ld.so.conf.d]# echo /usr/local/src/apr/lib/ >apr.conf
  61. [root@lnh ld.so.conf.d]# cd -
  62. /usr/local/src/apr
  63. //切换到前一个工作目录
  64. [root@lnh apr]# ldconfig
  65. //使命令生效
  66. [root@lnh apr]# ln -s /usr/local/src/apr/include/ /usr/include/apr
  67. [root@lnh apr]# ll /usr/include/apr
  68. lrwxrwxrwx. 1 root root 27 Jul 12 20:31 /usr/include/apr -> /usr/local/src/apr/include/
  69. //将头文件软链接到/usr/include目录下

安装apr-util

  1. [root@lnh xbz]# dnf -y install expat-devel libxml2-devel pcre-devel
  2. //需要先安装这个依赖
  3. [root@lnh xbz]# ls
  4. apr-1.7.0 apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz
  5. [root@lnh xbz]# tar -xf apr-util-1.6.1.tar.gz
  6. [root@lnh xbz]# ls
  7. apr-1.7.0 apr-util-1.6.1 httpd-2.4.54.tar.gz
  8. apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz
  9. //解压到当前目录
  10. [root@lnh xbz]# cd apr-util-1.6.1/
  11. [root@lnh apr-util-1.6.1]# ls
  12. aprutil.dep CHANGES include NWGNUmakefile
  13. aprutil.dsp CMakeLists.txt ldap README
  14. aprutil.dsw config.layout libaprutil.dep README.cmake
  15. aprutil.mak configure libaprutil.dsp README.FREETDS
  16. apr-util.pc.in configure.in libaprutil.mak redis
  17. apr-util.spec crypto libaprutil.rc renames_pending
  18. apu-config.in dbd LICENSE strmatch
  19. buckets dbm Makefile.in test
  20. build docs Makefile.win uri
  21. build.conf encoding memcache xlate
  22. buildconf export_vars.sh.in misc xml
  23. build-outputs.mk hooks NOTICE
  24. //进入源码包查看被解压出来的东西
  25. [root@lnh apr-util-1.6.1]# ./configure --prefix=/usr/local/src/apr-util --with-apr=/usr/local/src/apr
  26. ...
  27. configure: creating ./config.status
  28. config.status: creating Makefile
  29. config.status: creating export_vars.sh
  30. config.status: creating build/pkg/pkginfo
  31. config.status: creating apr-util.pc
  32. config.status: creating apu-1-config
  33. config.status: creating include/private/apu_select_dbm.h
  34. config.status: creating include/apr_ldap.h
  35. config.status: creating include/apu.h
  36. config.status: creating include/apu_want.h
  37. config.status: creating test/Makefile
  38. config.status: creating include/private/apu_config.h
  39. config.status: executing default commands
  40. //生成Makefile文件,需要伴随着上一个指定的依赖
  41. [root@lnh apr-util-1.6.1]# make
  42. ...
  43. gcc -E -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/root/xbz/apr-util-1.6.1/include -I/root/xbz/apr-util-1.6.1/include/private -I/usr/local/src/apr/include/apr-1 exports.c | grep "ap_hack_" | sed -e 's/^.*[)]\(.*\);$/\1/' >> aprutil.exp
  44. gcc -E -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/root/xbz/apr-util-1.6.1/include -I/root/xbz/apr-util-1.6.1/include/private -I/usr/local/src/apr/include/apr-1 export_vars.c | sed -e 's/^\#[^!]*//' | sed -e '/^$/d' >> aprutil.exp
  45. sed 's,^\(location=\).*$,\1installed,' < apu-1-config > apu-config.out
  46. make[1]: Leaving directory '/root/xbz/apr-util-1.6.1'
  47. //编译生成的Makefile文件,出现make[1]: Leaving directory '/root/xbz/apr-util-1.6.1'这个没有关系可以继续进行下一步安装
  48. [root@lnh apr-util-1.6.1]# make install
  49. ...
  50. See any operating system documentation about shared libraries for
  51. more information, such as the ld(1) and ld.so(8) manual pages.
  52. ----------------------------------------------------------------------
  53. /usr/bin/install -c -m 644 aprutil.exp /usr/local/src/apr-util/lib
  54. /usr/bin/install -c -m 755 apu-config.out /usr/local/src/apr-util/bin/apu-1-config
  55. //进行安装
  56. [root@lnh apr-util-1.6.1]# cd /usr/local/src/apr-util/
  57. [root@lnh apr-util]# ls
  58. bin include lib
  59. //切换到apr-util安装目录进行查看,默认情况下,系统搜索库文件的路径只有/lib,/usr/lib,我们需要进行修改在/etc/ld.so.conf.d/中创建以.conf为后缀名的文件,而后把要增添的路径直接写至此文件中。此时库文件增添的搜索路径重启后有效,若要使用增添的路径立即生效则要使用ldconfig命令
  60. [root@lnh apr-util]# cd /etc/ld.so.conf.d/
  61. [root@lnh ld.so.conf.d]# echo /usr/local/src/apr-util/ >apr-util.conf
  62. [root@lnh ld.so.conf.d]# cd -
  63. /usr/local/src/apr-util
  64. //切换到上一个工作目录
  65. [root@lnh apr-util]# ldconfig //使其生效
  66. [root@lnh apr-util]# ln -s /usr/local/src/apr-util/include/ /usr/include/apr-util
  67. [root@lnh apr-util]# ll /usr/include/apr-util
  68. lrwxrwxrwx. 1 root root 32 Jul 12 21:10 /usr/include/apr-util -> /usr/local/src/apr-util/include
  69. //将头文件软链接到/usr/include目录下

安装httpd

  1. [root@lnh xbz]# tar -xf httpd-2.4.54.tar.gz
  2. [root@lnh xbz]# ls
  3. apr-1.7.0 apr-util-1.6.1 httpd-2.4.54
  4. apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz
  5. //解压到当前目录
  6. [root@lnh xbz]# cd httpd-2.4.54/
  7. [root@lnh httpd-2.4.54]# ls
  8. ABOUT_APACHE CMakeLists.txt InstallBin.dsp README
  9. acinclude.m4 config.layout LAYOUT README.CHANGES
  10. Apache-apr2.dsw configure libhttpd.dep README.cmake
  11. Apache.dsw configure.in libhttpd.dsp README.platforms
  12. apache_probes.d docs libhttpd.mak ROADMAP
  13. ap.d emacs-style LICENSE server
  14. build httpd.dep Makefile.in srclib
  15. BuildAll.dsp httpd.dsp Makefile.win support
  16. BuildBin.dsp httpd.mak modules test
  17. buildconf httpd.spec NOTICE VERSIONING
  18. CHANGES include NWGNUmakefile
  19. changes-entries INSTALL os
  20. //查看被解压出来的东西
  21. [root@lnh httpd-2.4.54]# ./configure --prefix=/usr/local/src/httpd --with-apr=/usr/local/src/apr --with-apr-util=/usr/local/src/apr-util
  22. ...
  23. config.status: creating build/config_vars.sh
  24. config.status: creating include/ap_config_auto.h
  25. config.status: executing default commands
  26. configure: summary of build options:
  27. Server Version: 2.4.54
  28. Install prefix: /usr/local/src/httpd
  29. C compiler: gcc
  30. CFLAGS: -g -O2 -pthread
  31. CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
  32. LDFLAGS:
  33. LIBS:
  34. C preprocessor: gcc -E
  35. //生成Makefile文件
  36. [root@lnh httpd-2.4.54]# make
  37. ...
  38. /usr/local/src/apr/build-1/libtool --silent --mode=link gcc -g -O2 -pthread -o mod_rewrite.la -rpath /usr/local/src/httpd/modules -module -avoid-version mod_rewrite.lo
  39. make[4]: Leaving directory '/root/xbz/httpd-2.4.54/modules/mappers'
  40. make[3]: Leaving directory '/root/xbz/httpd-2.4.54/modules/mappers'
  41. make[2]: Leaving directory '/root/xbz/httpd-2.4.54/modules'
  42. make[2]: Entering directory '/root/xbz/httpd-2.4.54/support'
  43. make[2]: Leaving directory '/root/xbz/httpd-2.4.54/support'
  44. make[1]: Leaving directory '/root/xbz/httpd-2.4.54'
  45. //编译生成Makefile文件,出现的一些没有读取到的问题没有关系,继续进行下一步
  46. [root@lnh httpd-2.4.54]# make install
  47. ...
  48. Installing man pages and online manual
  49. mkdir /usr/local/src/httpd/man
  50. mkdir /usr/local/src/httpd/man/man1
  51. mkdir /usr/local/src/httpd/man/man8
  52. mkdir /usr/local/src/httpd/manual
  53. make[1]: Leaving directory '/root/xbz/httpd-2.4.54'
  54. //进行安装
  55. [root@lnh httpd-2.4.54]# cd /usr/local/src/httpd/
  56. [root@lnh httpd]# ls
  57. bin cgi-bin error icons logs manual
  58. build conf htdocs include man modules
  59. //切换到httpd的安装目录进行查看,默认情况下,系统搜索库文件的路径只有/lib,/usr/lib
  60. [root@lnh httpd]# ln -s /usr/local/src/httpd/include/ /usr/include/httpd
  61. [root@lnh httpd]# ll /usr/include/httpd
  62. lrwxrwxrwx. 1 root root 29 Jul 12 21:23 /usr/include/httpd -> /usr/local/src/httpd/include/
  63. //将头文件软链接到/usr/include目录下
  64. [root@lnh httpd]# echo "export PATH=$PATH:/usr/local/src/httpd/bin" > /etc/profile.d/httpd.sh
  65. [root@lnh httpd]# source /etc/profile.d/httpd.sh
  66. //配置httpd的全局环境变量,并生成效果
  67. [root@lnh httpd]# which httpd
  68. /usr/local/src/httpd/bin/httpd
  69. [root@lnh httpd]# vim /etc/man_db.conf
  70. MANDATORY_MANPATH /usr/man
  71. MANDATORY_MANPATH /usr/share/man
  72. MANDATORY_MANPATH /usr/local/share/man
  73. MANDATORY_MANPATH /usr/local/src/httpd/man
  74. //添加后面这一行
  75. [root@lnh ~]# httpd
  76. AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe57:f6f5%ens33\. Set the 'ServerName' directive globally to suppress this message
  77. httpd (pid 35719) already running
  78. //启动服务
  79. [root@lnh ~]# netstat -antp | grep httpd
  80. tcp6 0 0 :::80 :::* LISTEN 35719/httpd
  81. [root@lnh ~]# ss -antl
  82. State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
  83. LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
  84. LISTEN 0 128 *:80 *:*
  85. LISTEN 0 128 [::]:22 [::]:*
  86. //查看端口
  87. [root@lnh ~]# systemctl stop firewalld.service
  88. //关闭防火墙

服务80端口

file

将httpd服务加入systemd

  1. [root@lnh ~]# cd /usr/lib/systemd/system
  2. [root@lnh system]# cp sshd.service httpd.service
  3. [root@lnh system]# vim httpd.service
  4. [Unit]
  5. Description=httpd server daemon //服务
  6. After=network.target sshd-keygen.target
  7. [Service]
  8. Type=forking
  9. ExecStart=/usr/local/src/httpd/bin/httpd //服务安装的地方 开启
  10. ExecStop=/usr/local/src/httpd/bin/httpd -s stop //停止
  11. ExecReload=/bin/kill -HUP $MAINPID //重新加载并发出信号(对pid对组程序的进程号)可留可删
  12. [Install]
  13. WantedBy=multi-user.target
  14. [root@lnh system]# systemctl daemon-reload
  15. //重新加载一下并生效
  16. [root@lnh system]# systemctl status httpd.service
  17. httpd.service - httpd server daemon
  18. Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor >
  19. Active: inactive (dead)
  20. //查看一下是否有这个服务
  21. [root@lnh system]# ss -antl
  22. State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
  23. LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
  24. LISTEN 0 128 [::]:22 [::]:*
  25. //这里要确保之前的httpd这个80端口关了,此处没有就是关了
  26. [root@lnh system]# systemctl enable --now httpd.service
  27. Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service /usr/lib/systemd/system/httpd.service.
  28. //表示设置开机自启的同时候把它立刻启动
  29. [root@lnh system]# systemctl status httpd.service
  30. httpd.service - httpd server daemon
  31. Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor p>
  32. Active: active (running) since Tue 2022-07-12 23:15:02 CST; 2min 11s ago
  33. Process: 36389 ExecStart=/usr/local/src/httpd/bin/httpd (code=exited, sta>
  34. Main PID: 36390 (httpd)
  35. Tasks: 82 (limit: 11205)
  36. Memory: 24.3M
  37. CGroup: /system.slice/httpd.service
  38. ├─36390 /usr/local/src/httpd/bin/httpd
  39. ├─36391 /usr/local/src/httpd/bin/httpd
  40. ├─36392 /usr/local/src/httpd/bin/httpd
  41. └─36393 /usr/local/src/httpd/bin/httpd
  42. Jul 12 23:15:02 lnh systemd[1]: Starting httpd server daemon...
  43. Jul 12 23:15:02 lnh httpd[36389]: AH00558: httpd: Could not reliably determ>
  44. Jul 12 23:15:02 lnh systemd[1]: Started httpd server daemon.
  45. //查看状态,发现启动了并且也设置了开机自启
  46. [root@lnh system]# ss -antl
  47. State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
  48. LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
  49. LISTEN 0 128 *:80 *:*
  50. LISTEN 0 128 [::]:22 [::]:*
  51. //查看80端口
  52. [root@lnh system]# systemctl disable httpd.service
  53. Removed /etc/systemd/system/multi-user.target.wants/httpd.service.
  54. //关闭开机自启

file

源码编译报错信息处理

  1. checking for APR... no
  2. configure: error: APR not found. Please read the documentation.
  3. //解决方案
  4. [root@lnh xbz]# wget https://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz
  5. [root@lnh xbz]# wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
  6. 提前把这两个依赖包安装好才可以进行生成Makefile文件
  7. 无法进行生成两个依赖包的Makefile文件
  8. //解决方案
  9. [root@lnh xbz]# dnf -y install gcc gcc-c++ make wget
  10. 提前下载编译工具
  11. [root@lnh ~]# netstat -antp | grep httpd
  12. -bash: netstat: command not found
  13. //解决方案
  14. [root@lnh ~]# dnf provides netstat
  15. dnf -y install net-tools-2.0-0.52.20160912git.el8.x86_64
  16. //寻找需要的包并进行下载

本文转自:https://www.cnblogs.com/tushanbu/p/16473452.html

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议