ewr23 发表于 2015-6-8 09:27:52

centos下LAMP之源码编译安装httpd

1 最好先安装组件

1
2
# yum groupinstall additional development
# yum groupinstall development tool






2 安装ap1.5.2r(Apache Portable Runtime),安装apr-util 1.5.4工具

1
2
3
wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz
# tar xzvfapr-1.5.2.tar.gz
# ./configure --prefix=/usr/local/apr/




如果报错:rm: cannot remove `libtoolT': No such file or directory,请编辑configure这个文件,将 $RM "$cfgfile" 那行注释掉

1
#make&&make install





安装apr-util工具

1
wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz




编译选项注意有 --apr选项

1
2
3
4
# tar xf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
#make&&make install





3 centos默认安装了pcre,所以不需要安装pcre,否则请安装

4 安装httpd 2.4.12(2015-6-6新)

1
2
# tar xf httpd-2.4.12.tar.bz2
# cd httpd-2.4.12




打算编译选项加上(注意不明确的请查看./configure -h不要瞎写,写完和自己的对照一下,是否有问题)
基本选项,包括安装路径,配置文件路径
--prefix=/usr/local/apache指定安装的大路径
--sysconfdir=/etc/httpd指定配置文件的路径
模块允许选项,允许模块使用,大部分动态允许mpm等
--enable-so允许模块化使用
--enable-modules=most添加大多数的模块
--enable-mods-shared=most
--enable-mpms-shared=all支持所有的mpm模型
--enable-cgi --enable-cgid支持cgi程序
--enable-ssl支持ssl从而支持https
--enable-rewrite支持url重定向
指定和apr,apr-util的联系与绑定
--with-include-apr
--with-apr=/usr/local/apr指定apr
--with-apr-util=/usr/local/apr-util指定apr-util

1
2
# ./configure --prefix=/usr/local/apache--sysconfdir=/etc/httpd --enable-so --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --enable-cgi --enable-cgid --enable-ssl --enable-rewrite --with-include-apr --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
#make&&make install




编译安装完
进入安装后的目录

1
2
3
4
5
# cd /usr/local/apache
# ls
binbuildcgi-binerrorhtdocsiconsincludelogsmanmanualmodules
# cd bin/
# ./apachectl




然后打开网页试试,输入你的虚拟机ip即可
如果不能打开,考虑如下

1
2
3
4
5
# service iptables stop
# getenforce
Enforcing
# setenforce 0
# vim /etc/selinux/config




改为permissive
修改文件夹属性

1
#chmod 755 /usr/local/apache/




再刷新试试

上述的好了,网页出现it works!后

我们可以把命令复制到/etc/init.d/httpd实现service调用,总之,一切为了实现之前使用httpd rpm包的那个习惯,嘿嘿

1
2
# cp /root/httpd-2.4.12/build/rpm/httpd.init /etc/init.d/httpd
# chmod +x /etc/init.d/httpd




修改文件
建议三处

[*]httpd=${HTTPD-/usr/local/apache/bin/httpd}

[*]pidfile=${PIDFILE-/var/run/httpd/${prog}.pid}

[*]CONFFILE=/etc/httpd/httpd.conf



别急着启用服务
创建相应的目录

1
# mkdir /var/run/httpd/




为了使用httpd -t等命令,修改~/.bash_profile
修改为PATH=$PATH:$HOME/bin:/usr/local/apache/bin

1
2
3
4
# vim ~/.bash_profile
# source~/.bash_profile
# httpd -t
Syntax OK







在/etc/httpd/httpd.conf加上这行

PidFile "/var/run/httpd/httpd.pid"
为log文件创建符合链接

1
# ln -s /usr/local/apache/logs/* /var/log/httpd/




然后重启服务看是否ok
如果不行请查看日志文件等

1
2
3
# service httpd restart
Stopping httpd:                                          [ OK ]
Starting httpd:                                          [ OK ]




然后再次查看网页是否正常,最终搭建最新httpd2.4.12的任务已经完成!

页: [1]
查看完整版本: centos下LAMP之源码编译安装httpd