【04-02】 CentOS8 编译安装Apache http2.4
  gJgFk1CclRRT 2023年11月02日 39 0

【04-02】 CentOS8 编译安装Apache http2.4

不想看过程可以直接跳到最后的无脑运行环节

环境:

系统版本: CentOS Linux release 8.5.2111
内核版本: 4.18.0-348.el8.x86_64

编译测试:

前置设置

# 关闭防火墙
[root@centos8 ~]# systemctl disable --now firewalld
# 关闭SElinux
[root@centos8 ~]# sed -ri 's#^SELINUX=.*#SELINUX=enforcing#' /etc/selinux/config

1.安装wget,下载源码包

[root@centos8 ~]# yum install -y wget
[root@centos8 ~]# wget https://dlcdn.apache.org//httpd/httpd-2.4.51.tar.bz2
# 解压httpd到/usr/local/src目录 后发现缺少bzip2包
[root@centos8 ~]# tar xvf httpd-2.4.51.tar.bz2 -C /usr/local/src
tar (child): cannot run bzip2: 没有那个文件或目录
tar (child): trying lbzip2
tar (child): lbzip2:无法 exec: 没有那个文件或目录
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
# 搜索包来源
[root@centos8 ~]# yum provides bzip2
# 安装缺少的包
[root@centos8 ~]# yum install -y bzip2
# 解压到/usr/local/src目录
[root@centos8 ~]# tar xvf httpd-2.4.51.tar.bz2 -C /usr/local/src

 2.配置报错详情

[root@centos8 ~]# cd /usr/local/src/httpd-2.4.51/
# 尝试第一次安装
[root@centos8 httpd-2.4.51]# ./configure --prefix=/ProgramFiles/httpd --sysconfdir=/etc/httpd --enable-ssl
configure:
……
checking for APR... no
configure: error: APR not found. Please read the documentation.
# 报错后安装rpr-devel
# 第二次安装后报错
……
configure:
checking for APR-util... no
configure: error: APR-util not found. Please read the documentation.
# 报错后安装apr-util-devel
# 第三次安装后报错
……
checking whether the C compiler works... no
configure: error: in `/usr/local/src/httpd-2.4.51':
configure: error: C compiler cannot create executables
See `config.log' for more details
# 报错后安装gcc
# 第四次安装后报错
……
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
# 报错后安装pcre-devel
# 第五次安装后报错
………………
checking for OpenSSL... checking for user-provided OpenSSL base directory... none
checking for OpenSSL version >= 0.9.8a... FAILED
configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
# 报错后安装openssl-devel

# 再次执行后不再报错

3.编译并安装

# 进行编译并安装 2为cpu核数
[root@centos8 httpd-2.4.51]# make -j 2 && make install
-bash: make: 未找到命令
[root@centos8 httpd-2.4.51]# yum -y install make

#再次执行编译安装后报错
……
/etc/httpd/modules -module -avoid-version mod_authn_dbm.lo
gcc: error: /usr/lib/rpm/redhat/redhat-hardened-ld: No such file or directory
make[4]: *** [/usr/local/src/httpd-2.4.51/modules/aaa/modules.mk:2:mod_authn_file.la] 错误 1
make[4]: *** 正在等待未完成的任务....
gcc: error: /usr/lib/rpm/redhat/redhat-hardened-ld: No such file or directory
make[4]: *** [/usr/local/src/httpd-2.4.51/modules/aaa/modules.mk:4:mod_authn_dbm.la] 错误 1
make[4]: 离开目录“/usr/local/src/httpd-2.4.51/modules/aaa”
make[3]: *** [/usr/local/src/httpd-2.4.51/build/rules.mk:117:shared-build-recursive] 错误 1
make[3]: 离开目录“/usr/local/src/httpd-2.4.51/modules/aaa”
make[2]: *** [/usr/local/src/httpd-2.4.51/build/rules.mk:117:shared-build-recursive] 错误 1
make[2]: 离开目录“/usr/local/src/httpd-2.4.51/modules”
make[1]: *** [/usr/local/src/httpd-2.4.51/build/rules.mk:117:shared-build-recursive] 错误 1
make[1]: 离开目录“/usr/local/src/httpd-2.4.51”
make: *** [/usr/local/src/httpd-2.4.51/build/rules.mk:75:all-recursive] 错误 1
# 报错后安装redhat-rpm-config
[root@centos8 httpd-2.4.51]# yum -y install redhat-rpm-config

#再次编译并安装后安装成功
……
mkdir /ProgramFiles/httpd/cgi-bin
Installing header files
mkdir /ProgramFiles/httpd/include
Installing build system files
mkdir /ProgramFiles/httpd/build
Installing man pages and online manual
mkdir /ProgramFiles/httpd/man
mkdir /ProgramFiles/httpd/man/man1
mkdir /ProgramFiles/httpd/man/man8
mkdir /ProgramFiles/httpd/manual
make[1]: 离开目录“/usr/local/src/httpd-2.4.51”

4.配置环境

[root@centos8 ~]# echo 'PATH=/ProgramFiles/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
[root@centos8 ~]# . /etc/profile.d/httpd.sh

 

5.运行

[root@centos8 ~]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe9a:f5dc. Set the 'ServerName' directive globally to suppress this message
# 处理报错
[root@centos8 ~]# sed -r -i 's#^\#ServerName.*#ServerName localhost\:80#' /etc/httpd/httpd.conf

6.创建apache用户,并使用apache来运行

[root@centos8 ~]# useradd -r -s /sbin/nologin -d /var/www -c Apache apache
[root@centos8 ~]# sed -r -i -e 's#^User.*#User apache#' -e 's#^Group.*#Group apache#' /etc/httpd/httpd.conf

7.重启配置并生效

[root@centos8 ~]#apachectl restart

8.使用ps查看apache运行情况

[root@centos8 ~]# ps aux | grep apache

9.浏览器访问测试

【04-02】 CentOS8 编译安装Apache http2.4_apache

无脑执行:

经过前面部分测试后总结出的无脑安装法

安装依赖包
yum install -y wget bzip2 apr-devel apr-util-devel gcc pcre-devel openssl-devel make redhat-rpm-config

下载包
[root@centos8 ~]# wget https://dlcdn.apache.org//httpd/httpd-2.4.51.tar.bz2

[root@centos8 ~]# tar xvf httpd-2.4.51.tar.bz2 -C /usr/local/src
[root@centos8 ~]# mkdir /ProgramFiles
[root@centos8 ~]# cd /usr/local/src/httpd-2.4.51/
[root@centos8 httpd-2.4.51]# ./configure --prefix=/ProgramFiles/httpd --syscnotallow=/etc/httpd --enable-ssl
[root@centos8 httpd-2.4.51]# make -j 2 && make install
[root@centos8 httpd-2.4.51]# echo 'PATH=/ProgramFiles/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
[root@centos8 httpd-2.4.51]# . /etc/profile.d/httpd.sh
[root@centos8 httpd-2.4.51]# useradd -r -s /sbin/nologin -d /var/www -c Apache apache
[root@centos8 httpd-2.4.51]# sed -r -i -e 's#^User.*#User apache#' -e 's#^Group.*#Group apache#' -e 's#^\#ServerName.*#ServerName localhost\:80#' /etc/httpd/httpd.conf
[root@centos8 httpd-2.4.51]# apachectl start
[root@centos8 httpd-2.4.51]# ps aux | grep apache

 一键安装

systemctl disable --now firewalld;\sed -ri 's#^SELINUX=.*#SELINUX=enforcing#' /etc/selinux/config;\yum install -y wget bzip2 apr-devel apr-util-devel gcc pcre-devel openssl-devel make redhat-rpm-config;\wget https://dlcdn.apache.org//httpd/httpd-2.4.51.tar.bz2;\
tar xvf httpd-2.4.51.tar.bz2 -C /usr/local/src;\mkdir /ProgramFiles;\cd /usr/local/src/httpd-2.4.51/;\./configure --prefix=/ProgramFiles/httpd --syscnotallow=/etc/httpd --enable-ssl;\make -j 2 && make install;\echo 'PATH=/ProgramFiles/httpd/bin:$PATH' > /etc/profile.d/httpd.sh;\. /etc/profile.d/httpd.sh;\useradd -r -s /sbin/nologin -d /var/www -c Apache apache;\sed -r -i -e 's#^User.*#User apache#' -e 's#^Group.*#Group apache#' -e 's#^\#ServerName.*#ServerName localhost\:80#' /etc/httpd/httpd.conf;\apachectl start;\ps aux | grep apache

 

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  9E2BTpjt8nym   2023年12月06日   35   0   0 WindowsgitCentOS
gJgFk1CclRRT