Centos7通过源码编译的方式安装和配置Apache

一、下载软件包  (wget)

通过 https://apr.apache.org/  下载 APR 和 APR-util  //此网址不是直接的目标地址

通过 http://httpd.apache.org/download.cgi   下载 httpd   //此网址不是直接的目标地址

通过 https://ftp.pcre.org/pub/pcre/   下载  pcre   //此网址不是直接的目标地址

二、配置安装环境

yum -y install gcc gcc-c++ make expat-devel

三、解压与编译安装

mkdir /data

(1)编译安装 APR

tar xf apr-1.7.0.tar.gz -C /data

cd /data

mv apr-1.7.0/ apr 

cd apr/

./configure --prefix=/data/apr && make && make install

(2)编译安装 APR-util

tar xf apr-util-1.6.1.tar.gz -C /data

cd /data

mv apr-util-1.6.1/ apr-util

cd apr-util/

./configure --prefix=/data/apr-util --with-apr=/data/apr && make && make install

(3)编译安装 pcre

tar xf pcre-8.43.tar.gz -C /data

cd /data

mv pcre-8.43/ pcre

cd pcre/

./configure --prefix=/data/pcre && make && make install

(4)编译安装 httpd

tar xf httpd-2.4.41.tar.gz -C /data

cd /data

mv httpd-2.4.41/ apache

cd apache/

./configure --prefix=/data/apache --with-apr=/data/apr --with-apr-util=/data/apr-util && make && make install

四、启动与关闭

/data/apache/bin/apachectl start //启动

/data/apache/bin/apachectl  stop //关闭

 开放80端口

firewall-cmd --permanent --and-port=80/tcp

firewall-cmd -reload

配置开机自启

(1)将 apachectl 命令拷贝到 /etc/init.d 目录下,改名为httpd

cp /data/apache/bin/apachectl /etc/init.d/httpd

(2)编辑 /etc/init.d/httpd 文件,在第一行 #!/bin/bash 的后面添加如下两行

chkconfig: 2345 70 40

说明:2345 表示脚本运行的级别,即在2、3、4、5这4种模式下都可以运行,70 表示脚本启动的顺序号,40 表示系统关闭时,脚本的停止顺序号

description:apache

(3)将 Apache 服务加入到系统服务

chkconfig --add httpd

chkconfig --list httpd

(4)通过使用 systemctl 命令控制 Apache 的启动和停止

启动 Apache 服务

systemctl start httpd.service

查看 Apache 服务运行状态

systemctl status httpd.service

关闭 Apache 服务

systemctl stop httpd.service

五、安装中遇到的问题以及解决办法

错误:configure:error:no acceptable C compiler found in $PATH

解决:需要安装 gcc

错误:rm:cannot remove ‘libtoolT’:No such file or directory

解决:编辑 /data/apr/configure , 找到 $RM '$cfgfile' 进行注释

错误:configure:error:APR not found. Please read the documentation.

解决:需要安装 APR 和 APR-util

错误:xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录

解决:需要安装 expat-devel 包

错误:configure:error:pcre-config for libpcre not found. PCRE is required and availab le from

解决:需要安装 pcre

错误:如果报多个 .so:undefined reference to 'XXX'

解决:有可能是下载的 APR-util  包 有问题。换一个下载就好了。

 
没有借口
原文地址:https://www.cnblogs.com/wutao1935/p/11885000.html