参考:
https://blog.csdn.net/qq_30164225/article/details/54629763
https://blog.csdn.net/River_Crab/article/details/79732131
https://blog.csdn.net/lanwilliam/article/details/77848054
apache编译安装依赖包:apr,apr-util,pcre
ubuntu安装apache,版本:Ubuntu 18.04 LTS
#安装依赖包:
apt-get update
apt-install libssl-dev
apt-get install gcc
apt-get install g++
apt-get install make
#编译安装apr
./configure --prefix=/usr/local/apache2/apr
make -j4
make install
#编译安装apr-util
./configure --prefix=/usr/local/apache2/apr-util --with-apr=/usr/local/apache2/apr
make -j4
make install
#编译安装pcre
./configure --prefix=/usr/local/pcre
make -j4
make install
#编译安装apache,开启ssl等模块
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apache2/apr
--with-apr-util=/usr/local/apache2/apr-util/
--with-pcre=/usr/local/pcre --enable-so --enable-ssl
--enable-mods-shared=all --with-included-apr
make -j4
make install
#将apache做成系统服务
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
echo 'export PATH=$PATH:/usr/local/apache2/bin' > /etc/profile.d/httpd.sh
chmod a+x /etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh
centos7编译安装apache,版本:CentOS Linux release 7.4.1708 (Core)
下载安装包(根据官方下载页下载)
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz
wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.zip
wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.33.tar.gz
#解压安装包
tar -zxvf apr-1.6.3.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
tar -zxvf pcre-8.42.zip
unzip pcre-8.42.zip
#安装依赖包,如果没有安装开发工具包,需要先安装开发工具包
yum install expat-devel
yum install openssl -y
yum install openssl-devel.x86_64
#安装apr
cd apr-1.6.3/
./configure --prefix=/usr/local/apache2/apr
make -j4
make install
#安装apr-util
cd ..
cd apr-util-1.6.1/
./configure --prefix=/usr/local/apache2/apr-util --with-apr=/usr/local/apache2/apr
make -j4
make install
#安装pcre
cd pcre-8.42/
./configure --prefix=/usr/local/pcre
make -j4
make install
#把apr和apr-util的源码包(解压后)复制到httpd-2.4.33/srclib目录下
cd /root/httpd-2.4.33/srclib/
mkdir apr
mkdir apr-util
cp -r /root/apr-1.6.3/* ./apr
cp -r /root/apr-util-1.6.1/* ./apr-util/
#编译安装apache
./configure --prefix=/usr/local/apache2
--with-apr=/usr/local/apache2/apr
--with-apr-util=/usr/local/apache2/apr-util/
--with-pcre=/usr/local/pcre --enable-so --enable-ssl
--enable-mods-shared=all --with-included-apr
make -j4
make install
#把apache做成系统服务
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
echo 'export PATH=$PATH:/usr/local/apache2/bin' > /etc/profile.d/httpd.sh
chmod a+x /etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh
加入开机自启动参考:https://blog.csdn.net/nange_nice/article/details/76724037
在脚本(/etc/init.d/httpd)第二行加上如下注释
# chkconfig: 2345 61 39 #在脚本第二行开始添加
# description: Apache #centos6以后版本可加可不加,最好加上
chkconfig --add httpd
chkconfig httpd on #默认开启2345运行级别,当然可以通过选项--level num指定运行级别
chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off