1、安装相关的依赖包
yum -y install gcc make prce-devel openssl-devel expat-devel
2、安装apache之前需要安装好apr和apr-util
wget 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
./configure --prefix=/usr/local/apr #编译并指定目录
make && make install #安装apr
安装apr的时候会报以下的错误,解决方法很简单,打开configure这个文件,将RM='$RM'改成 RM='$RM -f '
安装apr-util,后面记得接上我们安装的apr的路径
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar xvf apr-util-1.6.1
cd apr-util-1.6.1
./configure --prefix=/usr/loca/apr-util --with-apr=/usr/local/apr
make && make install
下载apache的安装包,然后解压安装
wget https://mirror.bit.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
tar xvf httpd-2.4.46.tar.gz
cd http-2.4.46
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
make && make install
3、因为我们是编译安装的apache所以无法使用systemctl start httpd启动,这个时候我们可以通过./usr/local/apache/bin/apachectl start 启动,但是启动后会报如下图所示的错误,解决方法简单就是打开apache的配置文件httpd.conf,修改这一行ServerName localhost:80 ,即可。
4、这就表示访问成功了,如果访问不了的话,需要关闭一下防火墙systemctl stop firewalld
5、制作apache启动脚本,很简单的一个脚本httpd,基本看了就懂
function start_http()
{
/usr/local/apache/bin/apachectl start
}
function stop_http()
{
/usr/local/apache/bin/apachectl stop
}
function restart_http()
{
/usr/local/apache/bin/apchectl restart
}
case “$1” in
start)
start_http
;;
stop)
stop_http
;;
restart)
restart_http
;;
*)
echo “Usage:start | stop | restart”
;;
esac
6、启动自己所编写的脚本,脚本存放位置/etc/init.d/目录下,需要分配脚本执行权限,配置好之后我们就可以通过systemctl 启动我们的apache了
chmod + x httpd
systemctl daemon-reload
systemctl start httpd