---
title: "Centos7下编译安装Apache"
author: "yangle926"
date: "2018-11-09T17:01:13Z"
tags: ["Apache"]
categories: ["操作系统"]
slug: "centos7-apache"
draft: false
lastmod: "2018-11-09T17:01:13Z"
id: 2433572
url: "https://yangle926.iteye.com/blog/2433572"
---

参考：
	https://www.cnblogs.com/xhkj/p/6568379.html
	https://blog.csdn.net/qq_39591494/article/details/78726580
Apache至少需要apr、apr-util、pcre组件的支持。
http://mirrors.hust.edu.cn/apache/httpd/
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.37.tar.bz2
http://mirrors.hust.edu.cn/apache/apr/apr-1.6.5.tar.bz2
http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.bz2
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.bz2
# yum install -y bzip2
*** 编译安装apr
# tar -xjvf apr-1.6.5.tar.bz2
# cd apr-1.6.5
# ./configure --prefix=/usr/local/apr
# make && make install
*** 编译安装 apr-uril
# yum install -y expat-devel
# tar -xjvf apr-util-1.6.1.tar.bz2
# cd apr-util-1.6.1
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
***  编译安装pcre
# yum -y install pcre pcre-devel
# cd pcre-8.42
#  ./configure  -prefix=/usr/local/pcre
# make && make install
***  编译安装apache
# tar -xjvf httpd-2.4.37.tar.bz2
# cd httpd-2.4.37
# ./configure -prefix=/usr/local/apache24 -sysconfdir=/etc/httpd -enable-so -enable-rewrite -with-apr=/usr/local/apr -with-apr-util=/usr/local/apr-util -with-pcre=/usr/local/pcre
# make && make install
配置apache防火墙
# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload
# vi /etc/httpd/httpd.conf
 在#ServerName www.example.com:80 下增加下面的语句
 ServerName localhost:80
使用脚本控制Apache,启动服务
#  /usr/local/apache2/bin/apachectl start
#  /usr/local/apache2/bin/apachectl stop
#服务启动后，在浏览器输入http://localhost浏览器内容显示出it works，该内容存在于/usr/local/apache2/htdocs/index.html文件中
# /usr/local/apache24/bin/apachectl -M  ==列出启动的 Apache 模块。
# /usr/local/apache24/bin/apachectl status
	/usr/local/apache24/bin/apachectl:行95: lynx: 未找到命令
	解决:#yum -y install lynx
设置apache开机启动
方法一：将服务加到/etc/rc.d/rc.local中
# vi /etc/rc.d/rc.local
	/usr/local/apache24/bin/apachectl start  ==添加内容
# chmod +x /etc/rc.d/rc.local
相应的删除自启动方法　
	删除/etc/rc.d/rc.local中的/usr/local/apache24/bin/apachectl start这一行的内容，
	并且执行# chmod -x /etc/rc.d/rc.local
方法二：
1、将apachectl命令拷贝到/etc/init.d目录下，改名为httpd
# cp /usr/local/apache24/bin/apachectl /etc/init.d/httpd
2、编辑/etc/init.d/httpd文件，在第1行#!/bin/sh的后面添加如下两行
# vi /etc/init.d/httpd
# chkconfig: 2345 70 30   //注意：前面的#号是要保留的
# description: Apache //注意：前面的#号是要保留的
其中，所增加的第二行中三个数字，第一个表示在运行级别2345下启动Apache，第二、三是关于启动和停止的优先级配置。
3、Apache服务尚未被添加到chkconfig列表中，需要使用–add参数将其添加进去
# chkconfig --add httpd
# chkconfig --list httpd ==查看
相应的删除自启动方法
	# chkconfig --del httpd
	# rm -f /etc/init.d/httpd
