云服务器 源码部署apache网站服务器

简介:apache网站服务器的搭建

1、Apache简介:

Apache软件基金会的一个开源免费的网页服务器,也是目前世界上使用最广泛的一种web server ,apache最出名的 是它跨平台,高效和稳定,可以运行在几乎所有广泛使用的计算机平台上。其特点是简单、速度快、性能稳定,并可做代 理服务器来使用,并且可通过简单的 API 扩充,将 Perl/Python 等解释器编译到服务器中

2、源码编译安装 Apache:

先进入/usr/local/中创建三个文件夹 apr apr-util apache

cd /usr/local目录

mkdir apr 

mkdir apr-util 

mkdir apache
2.1、cd src 下载组件apr并解压:
组件apr官方网站:http://apr.apache.org/download.cgi 
wget http://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz 
tar -xf apr-1.7.0.tar.gz

在这里插入图片描述

2.2、cd src 下载组件apr-util并解压:
组件apr-util官方网站:http://apr.apache.org/download.cgi 
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz 
tar -xf apr-util-1.6.1.tar.gz

在这里插入图片描述

2.3、cd src 下载apache并解压:
apache官方网站:http://httpd.apache.org/download.cgi 
wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
tar -xf httpd-2.4.39.tar.gz

在这里插入图片描述

2.4、安装gcc环境:
yum install -y gcc*
2.5、安装xml 的解析器:
yum install -y expat-devel
2.6、安装OpenSSL密码库:
yum install  -y openssl-devel
2.7、下载并安装pcre正则表达式库:
(第一种)
yum install -y pcre pcre-devel

yum install pcre-devel
(第二种)
下载地址:https://ftp.pcre.org/pub/pcre/ 
tar -xf pcre-8.43.tar.gz 
cd pcre-8.43 
mkdir -p /usr/local/pcre 	#创建一个路径
./configure --prefix=/usr/local/pcre 	#指定一个安装路径,将pcre安装到指定目录
make && make install						#make编译 	make install安装

在这里插入图片描述

2.8、把组件apr与组件apr-util拷贝到apache安装包里:

首先进入到apache的解压安装包中
在这里插入图片描述

#在/root/softs/httpd-2.4.41/srclib目录下创建apr文件夹,强制(-rf)将apr-1.7.0赋值进去
cp -rf apr-1.7.0 /root/softs/httpd-2.4.41/srclib/apr			

cp -rf apr-util-1.6.1 /root/softs/httpd-2.4.41/srclib/apr-util
2.9、进入apache解压包进行./configure进行环境收集检验与配置相关模块:
cd  /root/softs/httpd-2.4.41
mkdir -p /usr/local/apache 
---------------------------------------------------------------------------------- 
./configure \--prefix=/usr/local/apache/ \--sysconfdir=/usr/local/apache/etc/ \--with- apr=/usr/local/src/apr-1.7.0 \--with-apr-util=/usr/local/src/apr-util-1.6.1 \--with-included-apr \--with-pcre=/usr/local/pcre \--enable-deflate=shared \--enable-expires=shared \--enable-headers \--enable-so \--enable-modules=most \--with-mpm=worker \--enable-rewrite=shared
---------------------------------------------------------------------------------- 
选项说明: 
--prefix 					#指定安装目录 
--sysconfdir 			#指定配置文件的路径 
--with-apr 				#指定依赖文件的路径 
--with-apr-util 			#指定依赖文件的路径 
--with-included-apr 			#增加编译效率的 
--with-pcre 						#指定pcre正则表达式库安装路径 
--enable-deflate 				#开启压缩文件提高速度节约带宽 
--enable-expires				#开启让浏览器缓存,减轻服务器压力,提高访问速度 
--enable-headers 			#使得支持http头 
--enable-so 						#使得支持动态模块 
--enable-modules=most 	#使得支持大多数模块 
--with-mpm=worker 		#使得Apache工作在worker模式下 
--enable-rewrite 				#使得支持地址重写

在这里插入图片描述

2.10、编译并安装apache:
make -j 4 && make install
2.11、设置服务器名称:
vi /usr/local/apache/etc/httpd.conf 
输入:ServerName进行搜索 
添加: ServerName www.fbiao.com
2.12、测试并启停apache服务器:
ln -s /usr/local/apache/bin/* /usr/sbin/ 			#设置软连接 
echo "export PATH=/usr/local/apache/bin:$PATH" >> /etc/profile 		#设置环境变量
source /etc/profile 		#加载环境变量 
httpd -t 						#测试配置文件语法有没有错误 
httpd -k start 				#启动apache服务 
httpd -k stop 				#关闭apache服务 

在防火墙关闭的条件下,打开浏览器,输入IP地址,成功打开apache测试页面
2.13、相关报错收集与解决办法:
(1)make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Entering directory `/home/test/apr-util-1.6.1'
/bin/sh /usr/local/apache/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread 
-DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE 
-I/home/test/apr-util-1.6.1/include -I/home/test/apr-util-1.6.1/include/private
- I/usr/local/apache/apr/include/apr-1
-o xml/apr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory

# include <expat.h> ^

compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/home/test/apr-util-1.6.1' 
make: *** [all-recursive] Error 1

错误原因:缺少xml 的解析器 
解决方法:yum -y install expat-devel
(2)configure 时 error: APR not found
错误详情: 
configure: checking for APR… no 
configure: error: APR not found. Please read the documentation.

错误原因:没有指定 Apache 必需组件 APR 或没有加–with-apr 选项指定 APR的安装位置。 
解决方法:安装 APR 并且加-–with-apr 选项指定正确的位置。
(3)configure 时-–with-apr 选项不正确
错误详情: 
configure: 
checking for APR… configure: error: –with-apr requires a directory or file to be provided 
configure: 
checking for APR… configure: error: the –with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file.

错误原因:-–with-apr 选项不能为空或者指定的 APR 的位置不正确 
解决方法:指定正确的 APR 选项。其实系统中已经使用 yum 安装了 APR,却不 知道如何指定 yum 安装的 APR 的位置,故出此错误,也可以进行手动源代码编译安装 APR来解决这个错误。
(4)configure 时 error: APR-util not found
错误详情: 
configure: checking for APR-util… no 
configure: error: APR-util not found. Please read the documentation.

错误原因:没有安装 Apache 必需组件 APR-util 或没有加–with-apr-util 选 项指定 APR-util 的位置 
解决方法:-–with-apr-util 选项指定正确的安装位置
(5)configure 时 error: pcre-config for libpcre not found
错误详情: 
checking for pcre-config… false 
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

错误原因:没有安装 Apache 必需组件 PCRE 或没有加–with-pcre 选项指定 PCRE 的安装位置。 
解决方法:安装 PCRE 并且加–with-pcre 选项指定正确的安装位置
(6)configure 时 error: Did not find pcre-config script at /usr/local/pcre2
错误详情: checking for pcre-config… false 
configure: error: Did not find pcre-config script at /usr/local/pcre2

错误原因: httpd 2.4.39 不支持 pcre2? 
解决方法:下载 pcre-8.43 安装即可。
(7)启动 Apache 时提示设置 ServerName
错误详情: 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

错误原因:没有设置服务器名称 
解决方法:vi /usr/local/apache/etc/httpd.conf
(8)启动 Apache 时提示设置 ServerName
错误详情: SELinux policy is not managed or store cannot be accessed.

错误原因:selinux是linux自带的保护机制
解决方法:vi /etc/sysconfig/selinux
建议关闭它
把里边的一行改为
SELINUX=disabled
改了之后保存,然后重启生效。
也可以使用setenforce 0 命令临时关闭

在这里插入图片描述

(9)SELinux导致Apache更改端口后无法启动
错误详情:SELinux导致Apache更改端口后无法启动

错误原因:selinux是linux自带的保护机制
解决方法:
(1)安装semanage
	(a)安装semanage,默认情况下,CentOS没有这个命令,需要查看这个命令由谁来提供的
			yum provides /usr/sbin/semanage
		然后进行安装
			yum -y install policycoreutils-python
	(b)semanage使用 针对prot context,例如查看ssh端口情况
			semanage port -l | grep ssh
		应该可以到如下结果:
			ssh_port_t                     tcp      2345, 22
(2)
	semanage port -l | grep http     # 查看现在支持的httpd端口
	
	http_port_t   tcp  80, 81, 443, 488, 8008, 8009, 8443, 9000

	可以看到http_port_t处没有90端口

在这里插入图片描述

(3)
	systemctl restart httpd     # 重新启动Apache服务器

	netstat -ntlp | grep http    # 查看端口状态,如下图,说明启动成功

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值