apache手册:http://httpd.apache.org/docs/current/install.html

在安装apache之前,需要先安装APR、APR-util、PCRE,另外Ubuntu需要安装libexpat1-dev,CentOS和RHEL需要安装expat-devel

获取安装包

apr / apr-util:http://mirrors.hust.edu.cn/apache/apr/http://mirror.bit.edu.cn/apache/apr/
pcre:https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
apache:http://mirrors.hust.edu.cn/apache/httpd/

依赖包安装

1)安装编译器gcc、gcc-c++
yum install -y gcc gcc-c++
2)安装依赖包expat-devel、zlib-devel、openssl-devel
yum install -y expat-devel zlib-devel openssl-devel
3) 安装依赖包apr

  1. tar zxvf apr-1.6.2.tar.gz
  2. cd apr-1.6.2
  3. ./configure --prefix=/usr/local/apr
  4. make && make install

3) 安装依赖包apr-util

  1. tar zxvf apr-util-1.6.0.tar.gz
  2. cd apr-util-1.6.0
  3. ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  4. make && make install

4) 安装依赖包pcre

  1. tar zxvf pcre-8.41.tar.gz
  2. cd pcre-8.41
  3. ./configure --prefix=/usr/local/pcre
  4. make && make install

Apache安装

1)解压

tar zxvf httpd-2.4.41.tar.gz
Apache - 图1

2)将apr、apr-util安装包拷贝到Apach

[root@centos7 opt]# cp -r apr-1.7.0 httpd-2.4.41/srclib/apr
[root@centos7 opt]# cp -r apr-util-1.6.1 httpd-2.4.41/srclib/apr-util

3)编译、安装

  1. cd httpd-2.4.41
  2. ./configure --prefix=/usr/local/server/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --with-mysql=shared,mysqlnd --enable-so --enable-ssl --enable-deflate --enable-rewrite --enable-headers --enable-expires --disable-cgid--disable-cgi
  3. make
  4. make install

4)修改配置文件httpd.conf

编辑 /usr/local/server/apache/conf/httpd.conf配置文件
去掉ServerName前面的 #,并将ServerName后面的网址改为localhost:80

5)将httpd加入系统服务并设置开机自启

将httpd加入系统服务:

  1. cp /usr/local/server/apache/bin/apachectl /etc/init.d/httpd
  2. ## 修改/etc/init.d/httpd,在第3行加入以下内容(注意: 代码中的 # 不可以去掉):
  3. # chkconfig: 345 85 15
  4. # description: Activates/Deactivates Apache Web Server

设置系统服务开机自启:
systemctl enable httpd

https://blog.csdn.net/weixin_42075590/article/details/80741211