阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下编译安装Apache及模块

125次阅读
没有评论

共计 3922 个字符,预计需要花费 10 分钟才能阅读完成。

Apache 是时下最流行的 Web 服务器软件之一,支持多平台,可快速搭建 web 服务,而且稳定可靠,并可通过简单的 API 扩充,就可以集成 PHP/Python 等语言解释器。文章这里讲解如何在 Linux 下编译 Apache,以及如何编译 Apache 模块。

Linux 下编译 Apache
下载 Apache 源代码,编译过程如下:
$ wget http://apache.fayea.com//httpd/httpd-2.4.12.tar.gz
$ tar -zxf httpd-2.4.12.tar.gz
$ cd httpd-2.4.12

$ ./configure –prefix=/usr/local/apache/
$ make && make install

编译过程中,可能会出现了以下错误:
$ ./configure –prefix=/usr/local/apache/checking for chosen layout… Apachechecking for working mkdir -p… yeschecking for grep that handles long lines and -e… /bin/grepchecking for egrep… /bin/grep -Echecking build system type… x86_64-unknown-linux-gnuchecking host system type… x86_64-unknown-linux-gnuchecking target system type… x86_64-unknown-linux-gnuconfigure:configure: Configuring Apache Portable Runtime library…configure:checking for APR… noconfigure: error: APR not found. Please read the documentation.
这里是因为 Apache 编译依赖 apr,没找到 apr 就无法正常安装。另外,Apache 还依赖 apr-util 和 pcre

编译 Apache 依赖
APR 是 Apache 可移植运行库,封装了所有操作系统调用,用来实现 Apache 内部组件对操作系统资源的使用,提高 Apache 的可移植性。APR 和 Apache 分离出来,避免 Apache 开发过程中,还要针对不同的平台做不同处理。apr-util 相当于 APR 工具集。PCRE 是实现正则的 perl 库。

编译和安装 APR
$ wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
$ tar -zxf apr-1.5.2.tar.gz
$ cd apr-1.5.2
$ ./configure –prefix=/usr/local/apr
$ make && make install

编译和安装 apr-util
$ wget http://archive.apache.org/dist/apr/apr-util-1.5.3.tar.gz
$ tar -zxf apr-util-1.5.3.tar.gz
$ cd apr-util-1.5.3
$ ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
$ make && make install

编译和安装 pcre
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
$ tar -zxf pcre-8.37.tar.gz
$ cd pcre-8.37
$ ./configure –prefix=/usr/local/pcre
$ make && make install

重新编译 Apache
安装 Apache 依赖后,编译时加多几个参数,重新编译 Apache
$ ./configure –prefix=/usr/local/apache/ \
–with-apr=/usr/local/apr \
–with-apr-util=/usr/local/apr-util \
–with-pcre=/usr/local/pcre
$ make && make install

编译 Apache 模块
这里以 mod_concatx 为例,说明如何编译 Apache 模块,步骤很简单。mod_concatx 是 apache 模块,可以用来合并多个 js/css,有效提高 js/css 加载速度
编译 mod_concatx 模块
$ wget http://apmod.googlecode.com/svn/trunk/mod_concatx/mod_concatx.c
$ ln -s /usr/local/apache/bin/apxs /usr/local/bin/apxs
$ apxs -c mod_concatx.c

编译并安装 mod_concatx 模块
$ apxs -iac mod_concatx.c

这种编译方式会自动安装 Apache 模块,安装成功后,可以在 Apache 模块目录找到 mod_concatx.so,并且 conf/httpd.conf 配置也会加上 mod_concatx 模块信息

启动 Apache
$ /usr/local/apache/bin/httpd -k start

注:Apache 启动后,以后台服务运行。如果想关闭 Apache,就使用以下命令:
$ /usr/local/apache/bin/httpd -k stop

查看已加载的 Apache 模块
$ /usr/local/apache/bin/httpd -M
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_event_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)
 concatx_module (shared)

说明 mod_concatx 已加载!

Apache 无法正常运行的解决办法
1. 80 端口被占用
$ netstat -anp | grep :80

找到占用端口的 Pid,kill 掉即可。

2. 防火墙默认禁用 80 端口
$ vi /etc/sysconfig/iptables

加多一行记录
-A RH-Firewall-1-INPUT -p tcp -m state –state NEW -m tcp –dport 80 -j ACCEPT
保存后,重启防火墙。
$ service iptables restart

Ubuntu Server 14.04 安装 Web 服务器(Linux+Apache+MySQL+PHP)  http://www.linuxidc.com/Linux/2015-06/119061.htm

Linux 下安装配置 PHP 环境(Apache2)  http://www.linuxidc.com/Linux/2015-05/118062.htm

Ubuntu 下 Apache 的 Rewrite 如何启用  http://www.linuxidc.com/Linux/2010-10/29027.htm

Ubuntu 14.04 中 Apache 2.2 升级到 2.4 后的几个要点 http://www.linuxidc.com/Linux/2015-01/111914.htm

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 5.9 下编译安装 LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm

RedHat 5.4 下 Web 服务器架构之源码构建 LAMP 环境及应用 PHPWind http://www.linuxidc.com/Linux/2012-10/72484p2.htm

LAMP 源码环境搭建 WEB 服务器 Linux+Apache+MySQL+PHP http://www.linuxidc.com/Linux/2013-05/84882.htm

Apache 的详细介绍:请点这里
Apache 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-06/11912.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计3922字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中