原文:https://www.s4lm0x.com/archives/40.htmlhtml
http://www.javashuo.com/article/p-fpkvcrax-dn.html----超详细 值得收藏 linux CentOS 7 配置Apache服务【转发+新增】linux
https://blog.51cto.com/13525470/2070375----CentOS 7 Apache服务的安装与配置c++
httpd
是使用排名第一的Web服务器软件. 它能够运行在几乎全部普遍使用的计算机平台上, 因为其跨平台和安全性被普遍使用, 是最流行的Web服务器端软件之一, 当前httpd版本为2.4.38
. 在CentOS 7
上使用yum
方式安装httpd是最简便的方式. 可是因为CentOS 7
自带的htpd版本固定, 有时咱们可能须要安装更新版本的httpd, 或者须要开启httpd默认未开启的功能模块, 此时编译httpd源码的安装方式将是咱们必须掌握的技能. 本文主要描述基于CentOS7. 6
以源码方式安装httpd-2.4.38
正则表达式
源码的编译安装通常由3个步骤组成shell
binutils
, glibc
, 配置软件特性, 检查编译环境, 生成 Makefile文件
./configure –-help
输出详细的选项列表编译安装的优势apache
操做系统安装时为
Minimal install
方式, 此时须要安装编译器以及编译器所依赖的软件包. 最直接的方式是将Development Tools
整个卡发包组安装, 但开发包组中不少的包是没必要要的, 故此只安装必要的软件包vim
使用阿里云的源安装相关编译环境windows
cd /etc/yum.repos.d curl -sO https://mirrors.aliyun.com/repo/epel-7.repo https://mirrors.aliyun.com/repo/Centos-7.repo yum clean all yum makecache fast
安装gcc以及相关依赖安全
yum install -y gcc glibc-devel zlib zlib-devel openssl-devel bzip2 bzip2-devel gcc-c++ expat-devel
PCRE
是Perl Compatible Regular Expression的缩写, 是一个Perl的正则表达式模块. HTTP核心模块和rewrite模块都会用到PCRE的正则表达式语法, 因此这个必须安装服务器
cd /usr/local/src curl -sO https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.bz2 tar xf pcre-8.43.tar.bz2 pcre-8.43 ./configure --prefix=/usr/local/pcre make -j 4 make install
httpd可在windows, linux, unix等多种平台部署, 而并不须要为每种平台都编写不一样的代码实现, 由于有apr、apr-util
apr
: apache portable runtime, 相似于JVM, PVM等虚拟机, 为apache提供运行环境. 针对不一样平台有不一样的apr, httpd经过不一样的apr,可运行于不一样的平台之上
apr-util
依赖于apr, 需先编译安装apr, 再编译安装apr-util
cd .. curl -sO http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.6.5.tar.bz2 tar xf apr-1.6.5.tar.bz2 cd apr-1.6.5 ./configure --prefix=/usr/local/apr make -j 4 && make install
cd .. curl -sO http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.bz2 tar xf 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
在httpd 2.4 中,
prefork
,worker
,event
做为模块, 可以使用配置文件切换在执行配置过程时可以使用disable, without, 显式地指定禁用哪些功能, 不依赖哪些程序包等
httpd 2.4中运行httpd的user, group也变成了daemon而不是apache, 因此在编译以前无需建立apache用户与组
cd .. curl -sO http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.38.tar.bz2 tar xf httpd-2.4.38.tar.bz2 cd httpd-2.4.38
include/ap_release.h
文件中的第40-46行vim include/ap_release.h #define AP_SERVER_BASEVENDOR "Apache Software Foundation" #服务的供应商名称 #define AP_SERVER_BASEPROJECT "Apache HTTP Server" #服务的项目名称 #define AP_SERVER_BASEPRODUCT "Apache" #服务的产品名 #define AP_SERVER_MAJORVERSION_NUMBER 2 #主要版本号 #define AP_SERVER_MINORVERSION_NUMBER 4 #小版本号 #define AP_SERVER_PATCHLEVEL_NUMBER 6 #补丁级别
./configure --prefix=/usr/local/httpd24 --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-layout=Apache --enable-load-all-modules --enable-so --enable-rewrite --enable-ssl --enable-cgi --with-zlib --enable-proxy --enable-proxy-http --disable-version make -j 4 make install
若是编译安装报错:
make[2]: *** [ab] 错误 1
make[2]: Leaving directory `/software/httpd-2.4.9/support'
make[1]: *** [all-recursive] 错误 1
make[1]: Leaving directory `/software/httpd-2.4.9/support'
make: *** [all-recursive] 错误 1
1.检查configure有没有添加--with-ssl=/usr/local/openssl-1.0.1g(从新编译安装后openssl的路径)的路径,添加后可解决以上报错的问题。
./configure --prefix=/home/apache-249 --enable-ssl --with-ssl=/usr/local/openssl-1.0.1g --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-rewrite --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event
若是不使用ssl,也能够在编译时候去掉--enable-ssl --with-ssl=/usr/local/openssl-1.0.1g,加上--disable-ssl 。
/usr/local/httpd24/bin
加入到系统PATH搜索路径中cd /usr/local/httpd24/bin echo 'PATH=$PATH:/usr/local/httpd24/bin' > /etc/profile.d/httpd.sh . /etc/profile.d/httpd.sh
http
服务被访问firewall-cmd --permanent --add-service=http firewall-cmd --reload
apachectl start curl 127.0.0.1
vim /usr/lib/systemd/system/httpd.service [Unit] Description=The Apache HTTP Server After=network.target remote-fs.target nss-lookup.target Documentation=man:httpd(8) Documentation=man:apachectl(8) [Service] Type=notify EnvironmentFile=/usr/local/httpd24/conf/httpd.conf ExecStart=/usr/local/httpd24/bin/apachectl $OPTIONS -DFOREGROUND ExecReload=/usr/local/httpd24/bin/apachectl $OPTIONS -k graceful ExecStop=/bin/kill -WINCH ${MAINPID} KillSignal=SIGCONT PrivateTmp=true [Install] WantedBy=multi-user.target
systemctl daemon-reload apachectl stop systemctl start httpd curl 127.0.0.1