编译安装Apache2.4.12
一、准备工作二、编译安装
三、相关文件路径配置
四、主配置文件常用配置信息详解
一、准备工作
安装编译环境
yum groupinstall "Development tools" 下载所需文件
# mkdir downloads
# cd downloads/
#wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.12.tar.gz
#wget http://mirror.bit.edu.cn/apache/apr/apr-1.5.2.tar.gz
#wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.5.4.tar.gz
# ls
apr-1.5.2.tar.gzapr-util-1.5.4.tar.gzhttpd-2.4.12.tar.gz 解压文件
# tar -xf httpd-2.4.12.tar.gz
# tar -xf apr-1.5.2.tar.gz
# tar -xf apr-util-1.5.4.tar.gz 二、编译安装
cd到源码文件夹中,可以使用 # ./configure --help,获取编译帮助
(1)、编译安装apr,apr-util,编译安装httpd2.4需要较新版本apr和apr-util
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr
# make && make install
# cd /root/downloads/apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
下列命令执行完成后
./configure --prefix=/usr/local/apr 结果中提示cannot remove `libtoolT': No such file or directory
解决编辑configure,注释掉 $RM "$cfgfile" 即可。
(2)、编译安装httpd
# cd /root/downloads/httpd-2.4.12
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=worker
# make
提示
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解决,下次编译时提前安装
# yum install pcre-devel -y
再次make,提示
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
解决,需要mod_ssl模块支持,依赖其开发组件
# yum install -y openssl-devel
再次make,成功,然后安装
# make install ./configure相关选项,--enable-mpms-shared=all,这样event、worker、prefork就会以模块化的方式安装,这里的--with-mpm=worker设定启用worker模块,其他的根据需要在httpd.conf里配置。
--sysconfdir=/etc/httpd:指定配置文件安装位置
--enable-so :支持动态共享模块如果没有这个模块PHP将无法与apache结合工作
--enable-ssl :启用支持ssl
--enable-cgi :支持cgi
--enable-rewrite :支持URL重写
--with-zlib :压缩库,在互联网上传播时可节约带宽
--with-apr=/usr/local/apr :指定apr路径
--with-apr-util=/usr/local/apr-util :指定apr-util路径
--enable-mpms-shared=all:支持多道处理模块
--with-mpm=event :设定默认的模块 补充:
(1)构建MPM为静态模块
在全部平台中,MPM都可以构建为静态模块。在构建时选择一种MPM,链接到服务器中。如果要改变MPM,必须重新构建。为了使用指定的MPM,请在执行configure脚本 时,使用参数 --with-mpm=NAME。NAME是指定的MPM名称。编译完成后,可以使用 ./httpd -l 来确定选择的MPM。 此命令会列出编译到服务器程序中的所有模块,包括 MPM。
(2)构建 MPM 为动态模块
在Unix或类似平台中,MPM可以构建为动态模块,与其它动态模块一样在运行时加载。 构建 MPM 为动态模块允许通过修改LoadModule指令内容来改变MPM,而不用重新构建服务器程序。在执行configure脚本时,使用--enable-mpms-shared选项即可启用此特性。当给出的参数为all时,所有此平台支持的MPM模块都会被安装。还可以在参数中给出模块列表。默认MPM,可以自动选择或者在执行configure脚本时通过--with-mpm选项来指定,然后出现在生成的服务器配置文件中。编辑LoadModule指令内容可以选择不同的MPM。
三、相关文件路径配置
1、修改httpd的主配置文件,设置其Pid文件的路径
编辑/etc/httpd/httpd.conf,添加如下行即可
Pidfile "/var/run/httpd.pid"
2、提供服务脚本
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
给脚本添加执行权限:
chmod +x /etc/rc.d/init.d/httpd
加入服务列表:
chkconfig --add httpd
chkconfig httpd on
service httpd start
启动服务若有如下提示
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message 编辑/etc/httpd/httpd.conf,搜索/ServerName,定位到#ServerName www.example.com:80,修改并启用即可,如
ServerName localhost:80 完成以上配置,就可以用浏览器测试了,下图中“It works!”显示apache正常工作
四、主配置文件常用配置信息详解
http://64314491.blog.51cto.com/2784219/1652056
页:
[1]