环境准备
这些包要提前安装,否则httpd编译安装时候会报错
openssl-devel pcre-devel expat-devel libtool gcc libxml2-devel
[root@node01 ~]# yum install openssl-devel pcre-devel expat-devel libtool gcc* libxml2-devel -y
下载源码、解压缩、软连接
1、wget下载
[root@node01 ~]# wget https://downloads.apache.org/httpd/httpd-2.4.57.tar.gz
--2023-07-20 12:49:02-- https://downloads.apache.org/httpd/httpd-2.4.57.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 135.181.214.104, 88.99.95.219, 2a01:4f9:3a:2c57::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|135.181.214.104|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9773385 (9.3M) [application/x-gzip]
Saving to: ‘httpd-2.4.57.tar.gz’
100%[===========================================================>] 9,773,385 3.50MB/s in 2.7s
2023-07-20 12:49:05 (3.50 MB/s) - ‘httpd-2.4.57.tar.gz’ saved [9773385/9773385]
2、解压缩
[root@node01 ~]# tar -zxf httpd-2.4.57.tar.gz -C /usr/local/cluster/
3、软连接
[root@node01 ~]# ln -s /usr/local/cluster/httpd-2.4.57/ /usr/local/cluster/httpd
编译安装需要两个依赖包
1、下载依赖包apr
[root@node01 ~]# wget https://downloads.apache.org/apr/apr-1.7.4.tar.gz
--2023-07-20 16:43:32-- https://downloads.apache.org/apr/apr-1.7.4.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f9:3a:2c57::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1122147 (1.1M) [application/x-gzip]
Saving to: ‘apr-1.7.4.tar.gz’
100%[===========================================================>] 1,122,147 933KB/s in 1.2s
2023-07-20 16:43:34 (933 KB/s) - ‘apr-1.7.4.tar.gz’ saved [1122147/1122147]
2、下载依赖包apr-util
[root@node01 ~]# wget https://downloads.apache.org/apr/apr-util-1.6.3.tar.gz
--2023-07-20 16:45:01-- https://downloads.apache.org/apr/apr-util-1.6.3.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f8:10a:201a::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 556623 (544K) [application/x-gzip]
Saving to: ‘apr-util-1.6.3.tar.gz’
100%[===========================================================>] 556,623 476KB/s in 1.1s
2023-07-20 16:45:03 (476 KB/s) - ‘apr-util-1.6.3.tar.gz’ saved [556623/556623]
[root@node01 ~]# ll -h apr*
-rw-r--r-- 1 root root 1.1M Apr 16 21:07 apr-1.7.4.tar.gz
-rw-r--r-- 1 root root 544K Feb 2 03:06 apr-util-1.6.3.tar.gz
编译安装apr
1、解压缩、创建软链接
[root@node01 ~]# tar -zxf apr-1.7.4.tar.gz -C /usr/local/cluster/
[root@node01 ~]# ln -s /usr/local/cluster/apr-1.7.4/ /usr/local/cluster/apr
[root@node01 ~]# cd /usr/local/cluster/apr
2、第一次编译报错
[root@node01 apr]# ./configure --prefix=/usr/local/apr
rm: cannot remove 'libtoolT': No such file or directory
修改文件configure,注释$RM "$cfgfile"
[root@node01 apr]# vim configure
# $RM "$cfgfile"
3、再次编译成功
[root@node01 apr]# ./configure --prefix=/usr/local/apr
。。。
configure: creating ./config.status
config.status: creating Makefile
config.status: creating include/apr.h
config.status: creating build/apr_rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating apr-1-config
config.status: creating apr.pc
config.status: creating test/Makefile
config.status: creating test/internal/Makefile
config.status: creating include/arch/unix/apr_private.h
config.status: executing libtool commands
config.status: executing default commands
config.status: include/apr.h is unchanged
config.status: include/arch/unix/apr_private.h is unchanged
4、执行make && make install
[root@node01 apr]# make && make install
。。。
----------------------------------------------------------------------
/usr/bin/install -c -m 644 apr.exp /usr/local/apr/lib/apr.exp
/usr/bin/install -c -m 644 apr.pc /usr/local/apr/lib/pkgconfig/apr-1.pc
for f in libtool shlibtool; do \
if test -f ${f}; then /usr/bin/install -c -m 755 ${f} /usr/local/apr/build-1; fi; \
done
/usr/bin/install -c -m 755 /usr/local/cluster/apr/build/mkdir.sh /usr/local/apr/build-1
for f in make_exports.awk make_var_export.awk; do \
/usr/bin/install -c -m 644 /usr/local/cluster/apr/build/${f} /usr/local/apr/build-1; \
done
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
编译安装apr-util
1、解压缩、创建软链接
[root@node01 ~]# tar -zxf apr-util-1.6.3.tar.gz -C /usr/local/cluster/
[root@node01 ~]# ln -s /usr/local/cluster/apr-util-1.6.3/ /usr/local/cluster/apr-util
[root@node01 ~]# cd /usr/local/cluster/apr-util
2、编译需要指定apr的目录 --with-apr=/usr/local/apr
[root@node01 apr-util]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
。。。
configure: creating ./config.status
config.status: creating Makefile
config.status: creating export_vars.sh
config.status: creating build/pkg/pkginfo
config.status: creating apr-util.pc
config.status: creating apu-1-config
config.status: creating include/private/apu_select_dbm.h
config.status: creating include/apr_ldap.h
config.status: creating include/apu.h
config.status: creating include/apu_want.h
config.status: creating test/Makefile
config.status: creating include/private/apu_config.h
config.status: executing default commands
3、执行make && make install
[root@node01 apr-util]# make && make install
报错提示需要安装expat包
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
#include <expat.h>
^
compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/usr/local/cluster/apr-util-1.6.3'
make: *** [all-recursive] Error 1
[root@node01 apr-util]# yum install expat-devel -y
4、再次执行成功
[root@node01 apr-util]# make && make install
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config
编译安装httpd
1、解压缩、创建软链接
[root@node01 ~]# tar -zxf httpd-2.4.57.tar.gz -C /usr/local/cluster/
[root@node01 ~]# ln -s /usr/local/cluster/httpd-2.4.57/ /usr/local/cluster/httpd
[root@node01 ~]# cd /usr/local/cluster/httpd
2、第一次编译报错
[root@node01 httpd]# ./configure --prefix=/usr/local/httpd --enable-so --enable-ssl --enable-cgi --enable--rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
报错需要pcre包
checking for pcre-config... no
configure: error: pcre(2)-config for libpcre not found. PCRE is required and available from http://pcre.org/
[root@node01 httpd]# yum install pcre-devel -y
3、再次执行成功
[root@node01 httpd]# ./configure --prefix=/usr/local/httpd --enable-so --enable-ssl --enable-cgi --enable--rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
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
4、提示OpenSSL版本过旧,升级OpenSSL
[root@node01 httpd]# yum install openssl-devel -y
5、再次编译成功
[root@node01 httpd]# ./configure --prefix=/usr/local/httpd --enable-so --enable-ssl --enable-cgi --enable--rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
configure: summary of build options:
Server Version: 2.4.57
Install prefix: /usr/local/httpd
C compiler: gcc -std=gnu11
CFLAGS: -g -O2 -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -std=gnu11 -E
6、执行make && make install报错
[root@node01 httpd]# make && make install
报错
/usr/local/apr/build-1/libtool --silent --mode=link gcc -std=gnu11 -g -O2 -pthread -o htpasswd htpasswd.lo passwd_common.lo /usr/local/apr-util/lib/libaprutil-1.la /usr/local/apr/lib/libapr-1.la -lrt -lcrypt -lpthread -ldl -lcrypt
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserFree'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetUserData'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] Error 1
make[2]: Leaving directory `/usr/local/cluster/httpd-2.4.57/support'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/cluster/httpd-2.4.57/support'
make: *** [all-recursive] Error 1
安装libtool依赖包
[root@node01 httpd]# yum install libtool -y
安装libxml2-devel依赖包
[root@node01 httpd]# yum install libxml2-devel -y
7、因为没有提前安装依赖包,需要重新编译安装apr-util,最后再重新编译安装httpd
参考文档https://my.oschina.net/LuCastiel/blog/1590706
8、删除apr-util安装目录,并重新编译安装
[root@node01 httpd]# rm -rf /usr/local/apr-util/
[root@node01 httpd]# cd /usr/local/cluster/apr-util
9、这一步很重要,必须清除之前配置时的缓存
[root@node01 apr-util]# make clean
10、再次重新编译安装apr-util
[root@node01 apr-util]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@node01 apr-util]# make && make install
11、重新编译安装httpd
[root@node01 apr-util]# cd /usr/local/cluster/httpd
[root@node01 httpd]# make clean
[root@node01 httpd]# ./configure --prefix=/usr/local/httpd --enable-so --enable-ssl --enable-cgi --enable--rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
configure: summary of build options:
Server Version: 2.4.57
Install prefix: /usr/local/httpd
C compiler: gcc -std=gnu11
CFLAGS: -g -O2 -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -std=gnu11 -E
12、再次执行make && make instal成功
[root@node01 httpd]# make && make instal
。。。
make[4]: Entering directory `/usr/local/cluster/httpd-2.4.57/modules/mappers'
make[4]: Nothing to be done for `local-shared-build'.
make[4]: Leaving directory `/usr/local/cluster/httpd-2.4.57/modules/mappers'
make[3]: Leaving directory `/usr/local/cluster/httpd-2.4.57/modules/mappers'
make[2]: Leaving directory `/usr/local/cluster/httpd-2.4.57/modules'
make[2]: Entering directory `/usr/local/cluster/httpd-2.4.57/support'
make[2]: Leaving directory `/usr/local/cluster/httpd-2.4.57/support'
Installing configuration files
mkdir /usr/local/httpd/conf
mkdir /usr/local/httpd/conf/extra
mkdir /usr/local/httpd/conf/original
mkdir /usr/local/httpd/conf/original/extra
Installing HTML documents
mkdir /usr/local/httpd/htdocs
Installing error documents
mkdir /usr/local/httpd/error
Installing icons
mkdir /usr/local/httpd/icons
mkdir /usr/local/httpd/logs
Installing CGIs
mkdir /usr/local/httpd/cgi-bin
Installing header files
mkdir /usr/local/httpd/include
Installing build system files
mkdir /usr/local/httpd/build
Installing man pages and online manual
mkdir /usr/local/httpd/man
mkdir /usr/local/httpd/man/man1
mkdir /usr/local/httpd/man/man8
mkdir /usr/local/httpd/manual
make[1]: Leaving directory `/usr/local/cluster/httpd-2.4.57'
启动httpd服务
1、查看httpd位置
[root@node01 httpd]# whereis httpd
httpd: /usr/local/httpd
2、启动httpd服务
[root@node01 ~]# cd /usr/local/httpd/bin
[root@node01 bin]# ./apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.6.101. Set the 'ServerName' directive globally to suppress this message
httpd (pid 548) already running
httpd已经运行
[root@node01 bin]# netstat -anp |grep httpd
tcp6 0 0 :::80 :::* LISTEN 548/httpd
[root@node01 bin]# ./apachectl stop
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.6.101. Set the 'ServerName' directive globally to suppress this message
3、修改配置文件
[root@node01 conf]# pwd
/usr/local/httpd/conf
[root@node01 conf]# vim httpd.conf
ServerName 192.168.6.101:80
[root@node01 bin]# ./apachectl stop
[root@node01 bin]# ./apachectl start
[root@node01 bin]# ps -ef |grep httpd
root 3236 1 0 18:52 ? 00:00:00 /usr/local/httpd/bin/httpd -k start
daemon 3237 3236 0 18:52 ? 00:00:00 /usr/local/httpd/bin/httpd -k start
daemon 3238 3236 0 18:52 ? 00:00:00 /usr/local/httpd/bin/httpd -k start
daemon 3239 3236 0 18:52 ? 00:00:00 /usr/local/httpd/bin/httpd -k start
daemon 3240 3236 0 18:52 ? 00:00:00 /usr/local/httpd/bin/httpd -k start
daemon 3241 3236 0 18:52 ? 00:00:00 /usr/local/httpd/bin/httpd -k start
root 3352 1706 0 18:52 pts/0 00:00:00 grep --color=auto httpd
4、查看httpd端口
[root@node01 bin]# netstat -anp | grep httpd
tcp6 0 0 :::80 :::* LISTEN 3236/httpd
配置systemctl管理服务
1、关闭httpd服务
[root@node01 ~]# /usr/local/httpd/bin/apachectl stop
[root@node01 ~]# ps -ef | grep httpd
root 7168 21465 0 13:12 pts/1 00:00:02 /usr/bin/python /usr/bin/yum list httpd
root 20985 7945 0 13:26 pts/3 00:00:00 grep --color=auto httpd
2、创建配置文件
[root@node01 ~]# vim /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=forking
ExecStart=/usr/local/httpd/bin/apachectl start
ExecReload=/usr/local/httpd/bin/apachectl graceful
ExecStop=/usr/local/httpd/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3、使用systemctl启动httpd服务
[root@node01 ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:httpd(8)
man:apachectl(8)
使用systemctl启动httpd
[root@node01 ~]# systemctl start httpd
[root@node01 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2023-08-11 13:32:10 CST; 6s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 27528 ExecStart=/usr/local/httpd/bin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 27531 (httpd)
CGroup: /system.slice/httpd.service
├─27531 /usr/local/httpd/bin/httpd -k start
├─27532 /usr/local/httpd/bin/httpd -k start
├─27533 /usr/local/httpd/bin/httpd -k start
├─27534 /usr/local/httpd/bin/httpd -k start
├─27535 /usr/local/httpd/bin/httpd -k start
└─27536 /usr/local/httpd/bin/httpd -k start
Aug 11 13:32:10 node01 systemd[1]: Starting The Apache HTTP Server...
Aug 11 13:32:10 node01 systemd[1]: Started The Apache HTTP Server.
4、设置开机自启
[root@node01 ~]# systemctl enable httpd
文章来源地址https://www.toymoban.com/news/detail-638292.html
文章来源:https://www.toymoban.com/news/detail-638292.html
到了这里,关于Apache2.4源码安装与配置的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!