Loading

Apache源码编译安装

安装相关依赖包

yum -y install wget gcc make pcre-devel openssl-devel expat-devel

编译安装

方法1

  1. 安装apr
tar xvf apr-1.7.0.tar.bz2
cd apr-1.7.0/

./configure --prefix=/apps/apr
# 这里可能会有如下所示报错,不影响。
# rm: cannot remove `libtoolT': No such file or directory 

make -j 2 && make install
  1. 安装apr-util
tar xvf apr-util-1.6.1.tar.bz2
cd apr-util-1.6.1/

./configure --prefix=/apps/apr-util --with-apr=/apps/apr

make -j 2 && make install
  1. 安装aptche
tar xvf httpd-2.4.46.tar.bz2
cd httpd-2.4.46/

./configure \
--prefix=/apps/httpd-2.4.46 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/apps/apr/ \
--with-apr-util=/apps/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork

make -j 2 && make install

方法2

  1. 将apr包和apr-util包解压后移动到httpd包下的srclib
tar xvf apr-1.7.0.tar.bz2
tar xvf apr-util-1.6.1.tar.bz2
tar xvf httpd-2.4.46.tar.bz2

mv apr-1.7.0 httpd-2.4.46/srclib/apr
mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
  1. 三者一起编译安装
cd httpd-2.4.46/

./configure \
--prefix=/apps/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork

make -j 2 && make install

配置httpd

# 创建apache账户
useradd -r -s /sbin/nologin apache

# 修改配置文件
[root@centos7 ~]#vim /apps/httpd24/conf/httpd.conf
User apache
Group apache

# 准备PATH变量
## 方法1
echo 'PATH=/apps/httpd24/bin:$PATH' >> /etc/profile.d/httpd24.sh
. /etc/profile.d/httpd24.sh

## 方法2
ln -s /apps/httpd24/bin/* /usr/sbin/

# 配置man帮助
echo "MANDATORY_MANPATH                       /apps/httpd24/man" >> /etc/man_db.conf

# 创建service文件
cat > /usr/lib/systemd/system/httpd24.service <<EOF
[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=/apps/httpd24/bin/apachectl start
ExecReload=/apps/httpd24/bin/apachectl graceful
ExecStop=/apps/httpd24/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

启动httpd

systemctl enable --now httpd24.service
posted @ 2020-11-03 10:46  吃一块云  阅读(133)  评论(0编辑  收藏  举报