创建一个test目录用于存放相关软件包
上传对应文件到服务器
下载组件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
下载组件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
下载apache并解压:
apache官方网站:http://httpd.apache.org/download.cgi
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.39.tar.gz
tar -xf httpd-2.4.39.tar.gz
我这里采用本地上传,上传成功如图
依次全部解压
安装gcc环境:
yum install -y gcc*
安装zlib-devel库
yum install -y zlib-devel
安装xml的解析器:
yum install -y expat-devel
下载正则表达式库(注意:apache不支持pcre2)
下载地址:https://ftp.pcre.org/pub/pcre
克隆多一个会话,上传解压:
创建目录,实现源码安装到指定目录输入以下三行命令即可
编译安装: make && make install
把组件apr与组件apr-util拷贝到apache安装包里
进入apache解压包进行./configure进行环境收集检验与配置相关模块:
进入下面目录:
cd /root/test/httpd-2.4.39
./configure \
--prefix=/usr/local/apache \
--sysconfdir=/usr/local/apache/etc \
--with-apr=/root/test/apr-1.7.0 \#注意路径要改成自己的路径,我的是在/root/下
--with-apr-util=/root/test/apr-util-1.6.1 \#注意路径要改成自己的路径,我的是在/root/下
--with-included-apr \
--with-pcre=/usr/local/pcre \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-so \
--enable-modules=most \
--with-mpm=worker \
--enable-rewrite
注意(参数含义):
./configure \ 当前目录执行httpd包中的configure脚本
--prefix=/usr/local/httpd \ 指定将 httpd 服务程序的安装文件路径
--enable-so \ 启用动态加载模块支持,使 httpd 具备进一步扩展功能的能力
--enable-rewrite \ 启用网页地址重写功能,用于网站优化、防盗链及目录迁移维护
--enable-charset-lite \ 启动字符集支持,以便支持使用各种字符集编码的页面
--enable-cgi 启用CGI(通用网关接口)脚本程序支持,便于网站的外部扩展应用访问能力
--enable-deflate \--enable-expires \ 提高性能
--enable-expires \缓存,加载缓存
编译并安装apache
make -j 4 && make install
查看apache文件
删除无用文件
设置服务器名称
先进入环境
搜索
搜索Servername
:/ServerName
找一个空白位置写入:ServerName www.baidu.com(随便一个网址)
保存退出 ::wq
添加软连接:apache中bin目录下的二进制文件软连接到/usr/sbin/
修改路径
vi /etc/profile
修改成如下图所示
或者采用追加的方式
然后cat
echo "export PATH=/usr/local/apache/bin:$PATH">>/etc/profile
cat /etc/profile
source /etc/profile //加载环境变量
浏览器访问
出现页面即安装成功
相关报错收集与解决办法:
(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/aprutil-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
5.7 CentOS7 实战源码部署nginx网站服务器
简介:实战演练nginx网站服务器的搭建
nginx 简介:
Nginx的优点:
Nginx的缺点:
编译安装:
安装gcc编译环境:
yum install -y gcc-c++
安装zlib-devel库:
yum install -y zlib-devel
安装OpenSSL密码库:
yum install -y openssl openssl-devel
错误原因: 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
错误原因:没有设置服务器名称