编译安装httpd 2.4
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编译安装httpd 2.4相关的知识,希望对你有一定的参考价值。
编译安装LAMP之:编译安装httpd 2.4
环境介绍:
系统环境:CentOS6.5
所需软件包:apr-1.5.2.tar.gz、apr-util-1.5.2.tar.gz、httpd-2.4.6.tar.gz
注意:httpd2.4需要依赖apr和arp-util 1.4以上版本
CentOS编译安装Apache准备:确保开发包组已安装(Development tools、Server Platform Development)
yum groupinstall "Development Tools" "Server Platform Development" -y
安装依赖:
1、下载官方源码包并解压:
httpd-2.4需要较新版本的apr(1.4以上)和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。这里选择使用编译源代码的方式进行。
wget http://archive.apache.org/dist/httpd/httpd-2.4.6.tar.bz2
wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
wget http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz
1.1 安装apr:
[[email protected] src]# tar xf apr-1.5.2.tar.gz
[[email protected] src]# cd apr-1.5.2.tar.gz
[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr
[[email protected] apr-1.5.2]# make
[[email protected] apr-1.5.2]# make install
说明:编译时报错提示 rm: cannot remove `libtoolT‘: No such file or directory
解决:直接打开 configure,把 $RM “$cfgfile” 那行删除掉,重新再运行 ./configure 就可以了。
1.2 安装apr-util
[[email protected] src]# tar xf apr-util-1.5.2.tar.gz
[[email protected] src]# cd apr-util-1.5.2
[[email protected] apr-util-1.5.2]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[[email protected] apr-util-1.5.2]# make
[[email protected] apr-util-1.5.2]# make install
编译说明:
--prefix指定安装路径;
--with-apr指定apr的安装路径,apr-util依赖于apr
2、编译安装httpd
2.1 安装依赖:
[[email protected] src]# yum -y install pcre-devel openssl-devel
2.2 编译安装
[[email protected] src]# tar xf httpd-2.4.6.tar.bz2
[[email protected] src]# cd httpd-2.4.6
[[email protected] httpd-2.4.6]# ./configure \
--prefix=/usr/local/apache \
--sysconfdir=/etc/httpd \
--enable-so \
--enable-rewrite \
--enable-ssl \
--enable-cgi \
--enable-cgid \
--with-zlib \
--with-pcre \
--enable-modules=most \
--enable-modules-shared=most \
--enable-mpms-shared=all \
--with-mpm=event \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util
[[email protected] httpd-2.4.6]# make
[[email protected] httpd-2.4.6]# make install
编译说明:
--prefix=/usr/local/apache :指定安装目标路径
--sysconfdir=/etc/httpd :指定配置文件安装位置
--enable-so :支持动态共享模块,如果没有这个模块php将无法与apache结合工作;DSO兼容,DSO=Dynamic Shared Object,动态共享对象,可实现模块动态生效
--enable-rewirte :支持URL重写
--enable-ssl :启用支持ssl 支持SSL/TLS,可实现https访问 需已安装openssl-devel
--enable-cgi :启用支持cgi (默认情况下启用非线程MPM)
--enable-cgid : 启用支持cgid (默认情况下启用线程MPM )
--with-zlib : 支持zlib压缩,传输层的压缩(不指定具体的路径,默认在系统中搜索)
--with-pcre : 支持正则化(不指定具体的路径,默认在系统中搜索)
--enable-modules=most :支持动态启用的模块,可选参数:all,most,few,reallyall
--enable-mods-shared=most :安装大多数共享模块,可选参数:all,most,few,reallyall (可选)
--enable-mpms-shared=all :支持全部多道处理方式
--with-mpm :#设置默认启用的MPM模式,{prefork|worker|event}
--with-apr=/usr/local/apr :指定apr路径
--with-apr-util=/usr/local/apr-util :指定apr-util路径
3、配置httpd 2.4(基于域名的虚拟主机)
[[email protected] ~]# vim /etc/httpd/httpd.conf
# DocumentRoot "/usr/local/apache/htdocs" # 注释掉DocumentRoot关闭主服务配置段
Include /etc/httpd/extra/httpd-vhosts.conf # 启用虚拟主机功能
4、配置虚拟主机配置文件
[[email protected] ~]# vim /etc/httpd/extra/httpd-vhosts.conf
<VirtualHost 192.168.100.11:80>
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache/htdocs/test1/"
ServerName test1.parparxy.com
ErrorLog "logs/test1-error_log"
CustomLog "logs/test1-access_log" common
</VirtualHost>
<VirtualHost 192.168.100.11:80>
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache/htdocs/test2/"
ServerName test2.parparxy.com
ErrorLog "logs/test2-error_log"
CustomLog "logs/test2-access_log" common
</VirtualHost>
5、生成测试网页
[[email protected] ~]# cd /usr/local/apache/htdocs/
[[email protected] htdocs]# mkdir test1 && echo "<h1> test1 </h1>" > test1/index.html
[[email protected] htdocs]# mkdir test2 && echo "<h1> test2 </h1>" > test2/index.html
6、测试脚本文件语法是否正确
[[email protected] ~]# ln -sv /usr/local/apache/bin/httpd /usr/bin/
`/usr/bin/httpd‘ -> `/usr/local/apache/bin/httpd‘
[[email protected] ~]# httpd -t
Syntax OK
7、为httpd执行文件创建PATH:
# vi /etc/profile.d/httpd.sh #添加如下一行
export PATH=$PATH:/usr/local/apache/bin
8、启动apache服务
[[email protected] httpd-2.4.6]# apachectl start
[[email protected] httpd-2.4.6]# netstat -tunlp | grep 80
tcp 0 0 :::80 :::* LISTEN 23850/httpd
[[email protected] httpd-2.4.6]#
9、头文件输出给系统:
# ln -sv /usr/local/apache/include /usr/local/include/httpd
10、为httpd执行文件创建PATH:
# vi /etc/profile.d/httpd.sh #添加如下一行
export PATH=$PATH:/usr/local/apache/bin让系统重新生成库文件路径缓存:
# ldconfig -v |grep "^[^[:space:]]"
11、为httpd执行文件创建PATH:
# vi /etc/profile.d/httpd.sh #添加如下一行
export PATH=$PATH:/usr/local/apache/bin为日志文件创建软连接:
# ln -fs /usr/local/apache/logs /var/log/httpd ##设置软链接以适应init脚本
# apachectl start 默认的启动apache方式
至此,就可以使用service httpd start 命令启动httpd了。
12、配置启动脚本:
[[email protected] httpd-2.4.6]# cp build/rpm/httpd.init /etc/init.d/httpd //使用init脚本管理httpd
[[email protected] httpd-2.4.6]# chmod 755 /etc/init.d/httpd //增加执行权限
[[email protected] httpd-2.4.6]# chkconfig --add httpd //添加httpd到服务开机启动
[[email protected] httpd-2.4.6]# ln -sf /usr/local/apache/bin/httpd /usr/sbin/httpd
问题:
Apache启动出现:
[[email protected] httpd-2.4.6] service httpd restart
AH00557: httpd: apr_sockaddr_info_get() failed for linux.64.114
AH00558: httpd: Could not reliably determine the server‘s fully qualified domain
name, using 127.0.0.1. Set the ‘ServerName‘ directive globally to suppress this
message
解决:
[[email protected] httpd-2.4.6] vi /server/apache/conf/httpd.conf
修改ServerName www.example.com:80 为 ServerName localhost:80
首次启动服务,80端口未被监听:
# cat /usr/local/apache/logs/error_log
报错提示:Resource Temporarily unavailable
解决:
# ulimit -u unlimited #修改 用户最大进程数
# echo ulimit -u unlimited >>/etc/profile #保存修改到自启动文件
本文出自 “眼眸刻着你的微笑” 博客,请务必保留此出处http://dengaosky.blog.51cto.com/9215128/1852827
以上是关于编译安装httpd 2.4的主要内容,如果未能解决你的问题,请参考以下文章