一、准备工作
二、编译安装
三、相关文件路径配置
四、主配置文件常用配置信息详解
一、准备工作
安装编译环境
?
1
| yum groupinstall "Development tools"
|
下载所需文件
?
解压文件
?
1
2
3
| [iyunv@localhost downloads]# tar -xf httpd-2.4.12.tar.gz
[iyunv@localhost downloads]# tar -xf apr-1.5.2.tar.gz
[iyunv@localhost downloads]# tar -xf apr-util-1.5.4.tar.gz
|
二、编译安装
cd到源码文件夹中,可以使用 # ./configure --help,获取编译帮助
(1)、编译安装apr,apr-util,编译安装httpd2.4需要较新版本apr和apr-util
?
1
2
3
4
5
6
| [iyunv@localhost apr-1.5.2]# cd apr-1.5.2
[iyunv@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr
[iyunv@localhost apr-1.5.2]# make && make install
[iyunv@localhost apr-1.5.2]# cd /root/downloads/apr-util-1.5.4
[iyunv@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[iyunv@localhost apr-util-1.5.4]# make && make install
|
下列命令执行完成后
?
1
| ./configure --prefix=/usr/local/apr
|
结果中提示cannot remove `libtoolT': No such file or directory
解决编辑configure,注释掉 $RM "$cfgfile" 即可。
(2)、编译安装httpd
?
1
2
3
4
5
6
7
8
9
10
11
12
13
| [iyunv@localhost apr-util-1.5.4]# cd /root/downloads/httpd-2.4.12
[iyunv@localhost 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
[iyunv@localhost httpd-2.4.12]# make
提示
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解决,下次编译时提前安装
[iyunv@localhost httpd-2.4.12]# 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模块支持,依赖其开发组件
[iyunv@localhost httpd-2.4.12]# yum install -y openssl-devel
再次make,成功,然后安装
[iyunv@localhost httpd-2.4.12]# make install
|
./configure相关选项,--enable-mpms-shared=all,这样event、worker、prefork就会以模块化的方式安装,这里的--with-mpm=worker设定启用worker模块,其他的根据需要在httpd.conf里配置。
?
1
2
3
4
5
6
7
8
9
10
| --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)、将服务程序路径添加到PATH环境变量中
新建/etc/profile.d/apache.sh,添加内容保存退出,source一下
?
1
| export PATH=$PATH:/usr/local/apache/bin
|
(2)、添加库文件搜索路径
新建/etc/ld.so.conf.d/apache.conf,添加内容
?
1
| /etc/ld.so.conf.d/apache.conf
|
(3)、添加头文件路径
?
1
| [iyunv@localhost profile.d]# ln -sv /usr/local/apache/include /usr/include/httpd
|
(4)、添加man手册路径
编辑/etc/man.config文件中的“MANPATH=”
?
1
| MANPATH /usr/local/apache/share/man
|
(5)、将服务脚本复制到/etc/init.d目录下
?
1
| [iyunv@localhost apache]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
|
(6)、有需要可以修改下/etc/init.d/httpd 1
2
3
| apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}
|
(7)、添加httpd到服务列表,设置开机启动,并启动服务
?
1
2
3
| [iyunv@localhost apache]# chkconfig --add httpd
[iyunv@localhost apache]# chkconfig httpd on
[iyunv@localhost apache]# service httpd start
|
如果有如下提示
?
1
| 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,修改并启用即可,如
?
1
| ServerName localhost:80
|
完成以上配置,就可以用浏览器测试了,下图中“It works!”显示apache正常工作
|