原文: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