編譯及安裝
$ wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.25.tar.gz
$ gzip -d httpd-2.4.25.tar.gz
$ tar xvf httpd-2.4.25.tar
$ cd httpd-2.4.25
$ ./configure --prefix=/usr/local/apache --enable-http --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=all --enable-mpms-shared=all --with-mpm=event --enable-cgid --enable-deflate=shared --enable-cache --enable-file-cache
$ make
$ make install
$ PREFIX/bin/apachectl -k start
注:PREFIX默認(rèn)為/usr/local/apache2
注解
--prefix=/usr/local/apache2 //體系無(wú)關(guān)文件的頂級(jí)安裝目錄PREFIX ,也就Apache的安裝目錄。
--enable-module=so //打開(kāi) so 模塊,so 模塊是用來(lái)提 DSO 支持的 apache 核心模塊
--enable-deflate=shared //支持網(wǎng)頁(yè)壓縮
--enable-expires=shared //支持 HTTP 控制
--enable-rewrite=shared //支持 URL 重寫(xiě)
--enable-cache //支持緩存
--enable-file-cache //支持文件緩存
--enable-mem-cache //支持記憶緩存
--enable-disk-cache //支持磁盤(pán)緩存
--enable-static-support //支持靜態(tài)連接(默認(rèn)為動(dòng)態(tài)連接)
--enable-static-htpasswd //使用靜態(tài)連接編譯 htpasswd - 管理用于基本認(rèn)證的用戶(hù)文件
--enable-static-htdigest //使用靜態(tài)連接編譯 htdigest - 管理用于摘要認(rèn)證的用戶(hù)文件
--enable-static-rotatelogs //使用靜態(tài)連接編譯 rotatelogs - 滾動(dòng) Apache 日志的管道日志程序
--enable-static-logresolve //使用靜態(tài)連接編譯 logresolve - 解析 Apache 日志中的IP地址為主機(jī)名
--enable-static-htdbm //使用靜態(tài)連接編譯 htdbm - 操作 DBM 密碼數(shù)據(jù)庫(kù)
--enable-static-ab //使用靜態(tài)連接編譯 ab - Apache HTTP 服務(wù)器性能測(cè)試工具
--enable-static-checkgid //使用靜態(tài)連接編譯 checkgid
--disable-cgid //禁止用一個(gè)外部 CGI 守護(hù)進(jìn)程執(zhí)行CGI腳本
--disable-cgi //禁止編譯 CGI 版本的 PHP
--disable-userdir //禁止用戶(hù)從自己的主目錄中提供頁(yè)面
--with-mpm=worker // 讓apache以worker方式運(yùn)行
--enable-authn-dbm=shared // 對(duì)動(dòng)態(tài)數(shù)據(jù)庫(kù)進(jìn)行操作。Rewrite時(shí)需要。
--enable-ssl 如果不加載將無(wú)法使用使用https
--enable-cgi 允許使用cgi腳本
--enable-rewrite 支持URL重寫(xiě)機(jī)制
--with-zlib 支持網(wǎng)絡(luò)通用壓縮庫(kù)
--with-pcre 支持pcre
--with-apr=/usr/local/apr 指定apr的安裝路徑
--with-apr-util=/usr/local/apr-util/ 指定apr-util的安裝路徑
--enable-modules=most 啟用大多數(shù)常用的模塊
--enable-mpms-shared=all 啟用MPM所有支持的模式
--with-mpm=event 默認(rèn)使用enevt模式
依賴(lài)
APR &&APR-Util
wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.gz
wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
#apr
gzip -d apr-1.5.2.tar.gz
tar xvf apr-1.5.2.tar
mv apr-1.5.2 httpd-2.4.25/srclib/apr
#apr-util
gzip -d apr-util-1.5.4.tar.gz
tar xvf apr-util-1.5.4.tar
mv apr-util-1.5.4 httpd-2.4.25/srclib/apr-util
注意:apr和apr-util不帶版本號(hào),且需放到指定目錄
PCRE
wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
gzip -d pcre-8.40.tar.gz
tar xvf pcre-8.40.tar
./configure
make
make install
注意:若報(bào)no acceptable C compiler found in $PATH錯(cuò)誤,安裝gcc和gcc-c++即可;make install時(shí)需要用管理員權(quán)限。
磁盤(pán)空間
大約需要50M的空間,大約10M用于HTTP服務(wù)器,其他的用于項(xiàng)目及第三方模塊
ANSI-C 編譯器 和 構(gòu)建系統(tǒng)
sudo apt-get install gcc g++
yum install gcc-c++
保持精準(zhǔn)的時(shí)鐘
通常,ntpdate 或 xntpd程序依賴(lài)于系統(tǒng)時(shí)間
下載
下載站點(diǎn)http://httpd.apache.org/download.cgi
編譯安裝mod_wsgi
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/modwsgi/mod_wsgi-3.4.tar.gz
gzip -d mod_wsgi-3.4.tar.gz
tar xvf mod_wsgi-3.4.tar
./configure -with-apxs=/usr/local/apache2/bin/apxs --enable-shared
make
make install
chmod 755 /usr/local/apache2/modules/mod_wsgi.so
服務(wù)目錄:/usr/local/apache2/bin/apachectl
加入自啟動(dòng):echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.local
生成控制腳本:grep -v "#" /usr/local/apache2/bin/apachectl > /etc/init.d/apache
添加chkconfig支持:vim /etc/init.d/apache
#!/bin/sh
# chkconfig: 2345 85 15
# description: Apache is a World Wide Webserver.
修改控制權(quán)限:chmod +x /etc/init.d/apache
添加到系統(tǒng)服務(wù):chkconfig --add apache
完成后,使用
#啟動(dòng)apache
service apache start
#關(guān)閉apache
service apache stop
添加防火墻例外:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart