准备工作
下载apr、apr-util、pcre、httpd包
-
- apr、apr-util下载, 如下图:
-
- pcre下载,如下图:
- pcre下载,如下图:
-
- httpd下载 ,如下图:
- httpd下载 ,如下图:
开始安装
1. 安装编译apr
[root@localhost ~]# cd /usr/local
[root@localhost local]# tar -zxvf apr-1.7.4.tar.gz -C ./
[root@localhost local]# cd apr-1.7.4/
[root@localhost apr-1.7.4]# ./configure --prefix=/usr/local/httpd/apr
[root@localhost apr-1.7.4]# make && make install
2. 编译安装apr-util
[root@localhost local]# tar -zxvf apr-util-1.6.3.tar.gz -C ./
[root@localhost local]# cd apr-util-1.6.3/
[root@localhost apr-util-1.6.3]#
[root@localhost apr-util-1.6.3]# ./configure --prefix=/usr/local/httpd/apr-util --with-apr=/usr/local/httpd/apr/bin/apr-1-config
[root@localhost apr-util-1.6.3]# make && make install
如果执行make && make install报错:
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
解决方案: 下载安装后再次执行make && make install
[root@localhost apr-util-1.6.3]# yum -y install expat-devel
3. 编译安装pcre
[root@localhost local]# tar -zxvf pcre-8.45.tar.gz -C ./
[root@localhost local]# cd pcre-8.45/
[root@localhost pcre-8.45]#
[root@localhost pcre-8.45]# ./configure --prefix=/usr/local/httpd/pcre --with-apr=/usr/local/httpd/apr/bin/apr-1-config
[root@localhost pcre-8.45]# make && make install
4.编译安装httpd
[root@localhost local]# tar -zxvf httpd-2.4.57.tar.gz -C ./
[root@localhost local]# cd httpd-2.4.57/
[root@localhost httpd-2.4.57]# ./configure --prefix=/usr/local/httpd/apache2.4 --with-apr=/usr/local/httpd/apr --with-apr-util=/usr/local/httpd/apr-util --enable-so --enable-mods-shared=most
[root@localhost httpd-2.4.57]# make && make install
如果执行make && make install报错:
…
/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] 错误 1
make[2]: 离开目录“/usr/local/src/httpd-2.4.28/support”
make[1]: *** [all-recursive] 错误 1
make[1]: 离开目录“/usr/local/src/httpd-2.4.28/support”
make: *** [all-recursive] 错误 1
解决方案参考: https://blog.51cto.com/castiel/2051440
5.修改httpd配置
[root@localhost httpd-2.4.57]# vi /usr/local/httpd/apache2.4/conf/httpd.conf
ServerName 你自己服务器ip:80
6.启动HTTP
6.1 将apachectl加入service系统服务
[root@localhost httpd-2.4.57]# cp /usr/local/httpd/apache2.4/bin/apachectl /etc/rc.d/init.d/apache
[root@localhost httpd-2.4.57]# chkconfig --add apache
service httpd does not support chkconfig
如果在此处遇到service httpd does not support chkconfig或服务 apache 不支持 chkconfig问题时,解决方法如下
[root@localhost httpd-2.4.57]# vi /etc/rc.d/init.d/apache
在第二行中添加如下代码
#chkconfig: 2345 10 90
#description: Activates/Deactivates Apache Web Server
6.2 启动apache服务
[root@localhost httpd-2.4.57]# service apache start
6.3 验证启动
[root@localhost httpd-2.4.57]# ps -ef | grep http
[root@localhost httpd-2.4.57]# netstat -an | grep :80
浏览器访问服务器ip地址
6.4 配置http环境变量
[root@localhost httpd-2.4.57]# vi /etc/profile
[root@localhost httpd-2.4.57]#
在最后一行添加如下代码
# HTTP_HOME
export HTTP_HOME=/usr/local/httpd/apache2.4
export PATH=$PATH:$HTTP_HOME/bin
6.5 验证HTTP环境
[root@localhost httpd-2.4.57]# source /etc/profile
[root@localhost httpd-2.4.57]# httpd -v
Server version: Apache/2.4.57 (Unix)
Server built: Oct 16 2023 11:16:49
[root@localhost httpd-2.4.57]#