您的位置:首页 > 理论基础 > 计算机网络

Unix下Apache HTTP编译及安装

2017-02-20 17:17 344 查看

编译及安装

$ 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默认为/usr/local/apache2

注解

–prefix=/usr/local/apache2 //体系无关文件的顶级安装目录PREFIX ,也就Apache的安装目录。

–enable-module=so //打开 so 模块,so 模块是用来提 DSO 支持的 apache 核心模块

–enable-deflate=shared //支持网页压缩

–enable-expires=shared //支持 HTTP 控制

–enable-rewrite=shared //支持 URL 重写

–enable-cache //支持缓存

–enable-file-cache //支持文件缓存

–enable-mem-cache //支持记忆缓存

–enable-disk-cache //支持磁盘缓存

–enable-static-support //支持静态连接(默认为动态连接)

–enable-static-htpasswd //使用静态连接编译 htpasswd - 管理用于基本认证的用户文件

–enable-static-htdigest //使用静态连接编译 htdigest - 管理用于摘要认证的用户文件

–enable-static-rotatelogs //使用静态连接编译 rotatelogs - 滚动 Apache 日志的管道日志程序

–enable-static-logresolve //使用静态连接编译 logresolve - 解析 Apache 日志中的IP地址为主机名

–enable-static-htdbm //使用静态连接编译 htdbm - 操作 DBM 密码数据库

–enable-static-ab //使用静态连接编译 ab - Apache HTTP 服务器性能测试工具

–enable-static-checkgid //使用静态连接编译 checkgid

–disable-cgid //禁止用一个外部 CGI 守护进程执行CGI脚本

–disable-cgi //禁止编译 CGI 版本的 PHP

–disable-userdir //禁止用户从自己的主目录中提供页面

–with-mpm=worker // 让apache以worker方式运行

–enable-authn-dbm=shared // 对动态数据库进行操作。Rewrite时需要。

–enable-ssl 如果不加载将无法使用使用https

–enable-cgi 允许使用cgi脚本

–enable-rewrite 支持URL重写机制

–with-zlib 支持网络通用压缩库

–with-pcre 支持pcre

–with-apr=/usr/local/apr 指定apr的安装路径

–with-apr-util=/usr/local/apr-util/ 指定apr-util的安装路径

–enable-modules=most 启用大多数常用的模块

–enable-mpms-shared=all 启用MPM所有支持的模式

–with-mpm=event 默认使用enevt模式

依赖

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不带版本号,且需放到指定目录

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


注意:若报
no acceptable C compiler found in $PATH
错误,安装gcc和gcc-c++即可;make install时需要用管理员权限。

磁盘空间

大约需要50M的空间,大约10M用于HTTP服务器,其他的用于项目及第三方模块

ANSI-C 编译器 和 构建系统

sudo apt-get install gcc g++
yum install gcc-c++


保持精准的时钟

通常,ntpdate 或 xntpd程序依赖于系统时间

下载

下载站点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


服务目录:
/usr/local/apache2/bin/apachectl


加入自启动:
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.


修改控制权限:
chmod +x /etc/init.d/apache


添加到系统服务:
chkconfig --add apache


完成后,使用

#启动apache
service apache start
#关闭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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: