引用文章地址
【摘要】 Apache HTTP Server(hpptd),简称Apache,是Apache软件基金会的一个开放源代码的网页服务器,可以在大多数电脑操作系统中运行,由于其具有的跨平台性和安全性,被广泛使用,是最流行的Web服务器端软件之一。
centos7.6
下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.43.tar.gz
hpptd安装依赖于apr,apr-util,pcre因此需要首先安装apr,apr-util,pcre。本文以apr-1.7.0,apr-util-1.6.1,pcre-8.44,httpd-2.4.43版本为例,下载源码,并编译安装:
wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.43.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
tar -xvf apr-1.7.0.tar.gz
cd apr-1.7.0
./configure
make
make install
tar -xvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install
tar -zxvf pcre-8.44.tar.gz
cd pcre-8.44
./configure --enable-utf8
make
make install
tar -zxvf httpd-2.4.43.tar.gz
cd httpd-2.4.43
./configure --prefix=/usr/local/httpd --with-pcre=/usr/local/pcre
make
make install
验证测试
进入安装目录,输入./httpd -v 查看版本
cd /usr/local/httpd/bin
./httpd -v
执行以下命令启动httpd服务
./apachectl start
回显信息如下:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
执行下列代码查看httpd进程,出现类似下面信息时,说明启动成功。
ps -ef|grep httpd
打开浏览器,在浏览器输入服务器IP测试,页面会显示It works!
配置文件路径: /usr/local/apache2/conf/httpd.conf
网站根目录: /usr/local/apache2/htdocs/
cp /usr/local/apache2/bin/apachectl /etc/init.d/
chmod +x /etc/init.d/apachectl
/etc/init.d/apachectl restart ## 启动方法一(简单快捷)
vim /usr/lib/systemd/system/apache.service
[Unit]
Description=apache
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/apachectl start
ExecReload=/etc/init.d/apachectl restart
ExecStop=/etc/init.d/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.targe
systemctl start apache.service
systemctl start apache.service
1)在安装apr时,使用./configure命令时,报如下错误:rm: cannot remove ‘libtoolT’: No such file or directory
解决方案:
将configure 文件中RM=‘ R M ′ 修 改 为 R M = ′ RM' 修改为RM=' RM′修改为RM=′RM -f’ 然后重新执行
./configure
make
make install
如下图:
2)在编译apr-util的时候,报如下错误,缺少expat库。
解决方案:
安装expat-deval库后,重新编译:
yum install expat-devel -y
#!/bin/bash
#auto install httpd
#by MR.xu 2020-07
#Httpd define path variable
H_FILES=httpd-2.4.43.tar.bz2
H_FILES_DIR=httpd-2.4.43
H_URL=https://mirrors.bfsu.edu.cn/apache//httpd/
H_PREFIX=/usr/local/apache2/
#auto install httpd
if [ -z "$1" ];then
echo -e "\033[36mplease select Install Menu follow:\033[0m"
echo -e "\033[32m1)编译安装Apache服务器\033[1m"
echo -e "\033[31mUsage: { /bin/sh $0 1|2|3|4|help}\033[0m"
exit
fi
if [[ "$1" -eq "1" ]];then
##安装工具
yum -y install wget tar bzip2;
##下载和安装apr以及apr-util
##先安装依赖包
yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
#安装apr基础可移植库
##本处下载的最新版本apr-1.7.0.tar.gz包
wget -c https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz;
##编译安装apr
tar -xvf apr-1.7.0.tar.gz&& cd apr-1.7.0;sed -i "/ RM='\$RM'/d" configure && sed -i "/\ ofile='\$ofile'/a\RM='\$RM \-f\'" configure;./configure --prefix=/usr/local/apr
if [ $? -eq 0 ];then
make&& make install
echo -e "\033[32mThe apr-1.7.0 install successfully!\033[0m"
else
echo -e "\033[32mThe apr-1.7.0 install failed,please check...!\033[0m"
exit
fi
#安装apr-util
wget -c https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz;
##编译安装apr-util
tar -xvf apr-util-1.6.1.tar.gz&& cd apr-util-1.6.1;./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
if [ $? -eq 0 ];then
make&& make install
echo -e "\033[32mThe apr-util-1.6.1 install successfully!\033[0m"
else
echo -e "\033[32mThe apr-util-1.6.1 install failed,please check...!\033[0m"
exit
fi
#安装pcre
wget -c https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz;
##编译安装pcre
tar -xvf pcre-8.44.tar.gz&& cd pcre-8.44;./configure --enable-utf8
if [ $? -eq 0 ];then
make&& make install
echo -e "\033[32mThe pcre-8.44 install successfully!\033[0m"
else
echo -e "\033[32mThe pcre-8.44 install failed,please check...!\033[0m"
exit
fi
#安装httpd
wget -c $H_URL/$H_FILES;
##编译安装httpd
tar -jxvf $H_FILES &&cd $H_FILES_DIR ;./configure --prefix=$H_PREFIX --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
if [ $? -eq 0 ];then
make &&make install
echo -e "\033[32mThe $H_FILES_DIR sever install successfully!\033[0m"
echo -e "\033[32m查看版本,并启动httpd server !\033[0m"
cd $H_PREFIX/bin/;./httpd -v;./apachectl start;
echo -e "\033[32m查看httpd server!进程\033[0m"
ps -ef|grep httpd;
else
echo -e "\033[32mThe $H_FILES_DIR sever install failed,please check...!\033[0m"
exit
fi
fi