CentOS编译安装Apache2.4.46

#安装编译环境
yum install gcc make autoconf gcc-c++ glibc glibc-devel pcre pcre-devel expat-devel
因为httpd2.4.46需要openssl v1.1.1版本。centos7yum仓库的版本太老不支持

#下载openssl,解压
wget https://www.openssl.org/source/old/1.1.1/openssl-1.1.1h.tar.gz
tar xvf openssl-1.1.1h.tar.gz
#编译安装到指定目录/app/openssl下
cd ~/openssl-1.1.1h
./config --prefix=/app/openssl
make && make install
#配置环境
echo “/app/openssl/lib/” >> /etc/ld.so.conf
ldconfig -v
echo ‘export PATH=/app/openssl/bin:$PATH’ > /etc/profile.d/openssl.sh
. /etc/profile.d/openssl.sh
这也是最新版httpd的要求不然编译的时候会报错。

#下载apr包,解压
wget https://mirror.dsrg.utoronto.ca/apache//apr/apr-1.7.0.tar.bz2
tar xvf apr-1.7.0.tar.bz2
cd apr-1.7.0
#编译安装
./configure --prefix=/usr/
make && make install
#跟上面一下下载,解压
wget https://mirror.dsrg.utoronto.ca/apache//apr/apr-util-1.6.1.tar.bz2
tar xvf apr-util-1.6.1.tar.bz2
#编译安装
./configure --prefix=/app/util --with-apr=/usr/bin/apr-1-config --enable-utf8
make && make install
上面的环境升级完后才可进行这一步,不然会报错的。

#下载包,解压
wget https://mirror.its.dal.ca/apache//httpd/httpd-2.4.46.tar.bz2
tar xvf httpd-2.4.46.tar.bz2
cd httpd-2.4.46
#编译安装到/app/httpd24目录
./configure --prefix=/app/httpd24/ --with-apr=/app/apr/ --with-apr-util=/app/apr-util/ --with-pcre=/app/pcre/
make && make install
报错:httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName
解决方案:
找到#ServerName www.example.com:80 把#去掉,然后改成 ServerName 127.0.0.1:80再重啟apache即可沒事了。

启动apache服务
/app/httpd24/bin/apachectl start

添加httpd服务
如Apache安装路径为:/usr/local/apache
Linux的启动级别为5,版本为CentOS5Apache安装完后,发现Apache无法自动启动,查看/etc/rc.d/rc5.d/下,应该没有S打头,httpd结尾的链接文件。
1、将apachectl文件拷贝到/etc/rc.d/init.d 中,然后在/etc/rc.d/rc5.d/下加入链接即可。
命令如下:
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd //如果有其他的版本的Apache存在,也可以直接覆盖掉
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc5.d/S85httpd //建立链接(85的意义后面介绍)
此时Apache就可以自动启动了。
2、运行chkconfig --list,发现没有linux服务列表中httpd,通过chkconfig --add httpd来添加,但是提示:httpd服务不支持 chkconfig。需要编辑/etc/rc.d/init.d/httpd,添加以下注释信息:

chkconfig: 345 85 15

descrīption: Apache

第一行3个数字参数意义分别为:哪些Linux级别需要启动httpd(3,4,5);启动序号(85);关闭序号(15)。
保存后执行:chkconfig --add httpd,成功添加。
在rc3.d、rc4.d、rc5.d路径中会出现S85httpd的链接文件,其他运行级别路径中会出现K61httpd的链接文件。
3、运行chkconfig --list,httpd在其中
备注
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc5.d/S85httpd //建立链接
中,rc3.d、rc4.d、rc5.d要和参数345对应

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值