httpd-2.4.6.tar.bz2,apr-1.4.6.tar.bz2,apr-util-1.5.2.tar.bz2,pcre-8.34.tar.bz2
编译安装pcre时需要gcc-c++
[root@Machine1 ~]# yum install gcc [root@Machine1 pcre-8.34]# yum install gcc-c++
--prefix=PATH:指定安装路径
[root@Machine1 ~]# tar xf apr-1.4.6.tar.bz2 [root@Machine1 ~]# cd apr-1.4.6 [root@Machine1 apr-1.4.6]# ./configure --prefix=/usr/local/apr146 [root@Machine1 apr-1.4.6]# echo $? 0 [root@Machine1 apr-1.4.6]# make && make install [root@Machine1 apr-1.4.6]# echo $? 0 [root@Machine1 ~]# tar xf apr-util-1.5.2.tar.bz2 [root@Machine1 ~]# cd apr-util-1.5.2 [root@Machine1 apr-util-1.5.2]# ./configure --prefix=/usr/local/aprutil152 --with-apr=/usr/local/apr146/ [root@Machine1 apr-util-1.5.2]# echo $? 0 [root@Machine1 apr-util-1.5.2]# make && make install [root@Machine1 apr-util-1.5.2]# echo $? 0 [root@Machine1 ~]# tar xf pcre-8.34.tar.bz2 [root@Machine1 ~]# cd pcre-8.34 [root@Machine1 pcre-8.34]# ./configure --prefix=/usr/local/pcre834 [root@Machine1 pcre-8.34]# echo $? 0 [root@Machine1 pcre-8.34]# make && make install [root@Machine1 pcre-8.34]# echo $? 0
--prefix=PATH #安装路径
--sysconfdir=PATH #配置文件路径
--enable-modules=MODULE-LIST #启用哪些模块all , most , few
--enable-mods-shared=MODULE-LIST #编译成动态共享模块all , most ,few
--enable-mods-static=MODULE-LIST #静态编译进httpd
--enable-ssl #启用支持ssl
--enable-mpms-shared=MPM-LIST #把哪些mpm编译为动态共享模快
--with-mpm=MPM #httpd默认使用的MPM=prefork,worker,event
--enable-cgi #启用cgi
--enable-rewrite #支持url重写
--enable-so #启用动态模块支持
--with-zlib #支持zlib库
[root@Machine1 ~]# tar xf httpd-2.4.6.tar.bz2 [root@Machine1 ~]# cd httpd-2.4.6[root@Machine1 httpd-2.4.6]# ./configure \ > --prefix=/usr/local/httpd246 \ > --sysconfdir=/etc/httpd24 \ > --enable-so \ > --enable-ssl \ > --enable-cgi \ > --with-zlib \ > --enable-rewrite \ > --enable-modules=most \ > --enable-mods-shared=most \ > --enable-mpms-shared=all \ > --with-mpm=event \ > --with-apr=/usr/local/apr146 \ > --with-apr-util=/usr/local/aprutil152 \ > --with-pcre=/usr/local/pcre834 \
********************************************************** 可能出现的报错: *checking for OpenSSL version >= 0.9.7... FAILED *configure: WARNING: OpenSSL version is too old *no *checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures *解决方法: *[root@Machine1 httpd-2.4.6]# yum -y install openssl-devel ***********************************************************
[root@Machine1 httpd-2.4.6]# echo $? 0 [root@Machine1 httpd-2.4.6]# make && make install [root@Machine1 httpd-2.4.6]# echo $? 0
导出头文件: [root@Machine1 httpd246]# ln -sv /usr/local/httpd246/include /usr/include/httpd `/usr/include/httpd' -> `/usr/local/httpd246/include' 导出bin目录: [root@Machine1 httpd246]# echo 'export PATH=/usr/local/httpd246/bin:$PATH' > /etc/profile.d/httpd.sh [root@Machine1 httpd246]# cat /etc/profile.d/httpd.sh export PATH=/usr/local/httpd246/bin:$PATH [root@Machine1 httpd246]# . /etc/profile.d/httpd.sh 导出man文档: [root@Machine1 httpd246]#vim /etc/man.config MANTPATH /usr/local/httpd246/man
[root@Machine1 httpd246]# apachectl [root@Machine1 httpd246]# hash hits command 3 /usr/bin/vim 1 /usr/bin/killall 1 /usr/local/httpd246/bin/httpd 1 /bin/ln 2 /usr/local/httpd246/bin/apachectl [root@Machine1 httpd246]# curl http://localhost <html><body><h1>It works!</h1></body></html>
简单写的一个脚本,可以实现start、stop、restart和reload功能:
[root@Machine1 ~]# cat httpd.sh #!/bin/bash # #chkconfig - 85 15 # #by: wsh #Source function library . /etc/rc.d/init.d/functions pidfile=/var/run/httpd24/httpd.pid lockfile=/var/lock/subsys/httpd prog=httpd httpd=/usr/local/httpd246/bin/httpd start(){ echo -n "Starting $prog:" daemon $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch $lockfile $pidfile return $RETVAL } stop(){ echo -n "Stopping $prog:" killproc $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f $pidfile $lockfile } reload(){ echo -n "Reloading $prog:" killproc $httpd -HUP RETVAL=$? echo } case $1 in start) start;; stop) stop;; restart) stop start;; reload) reload;; *) echo "Usage:start|stop|restart|reload" esac
添加执行权限:
[root@Machine1 ~]# chmod +x httpd.sh
移动至/etc/rc.d/init.d/下,以便可以使用service管理httpd:
[root@Machine1 ~]# mv httpd.sh /etc/rc.d/init.d/httpd24
测试:
[root@Machine1 ~]# service httpd24 start Starting httpd: [ OK ] [root@Machine1 ~]# ss -tanl | grep "80" LISTEN 0 128 :::80 :::* [root@Machine1 ~]# service httpd24 stop Stopping httpd: [ OK ] [root@Machine1 ~]# ss -tanl | grep "80" [root@Machine1 ~]# service httpd24 start Starting httpd: [ OK ] [root@Machine1 ~]# service httpd24 restart Stopping httpd: [ OK ] Starting httpd: [ OK ] [root@Machine1 ~]# service httpd24 reload Reloading httpd: [ OK ]