实验环境准备:
官网http://www.apache.org/下载源代码httpd2.4,以及相关依赖包apr-1.6.2,apr-util-1.6.0
准备没有安装过httpd任何版本的centos6.9系统
安装开发包
]#yum install openssl-devel -y
]#yum install pcre-devel -y
]#yum install expat-devel -y
上传源代码并解压缩
]#cd /appapp]#rz app]#tar xvf apr-1.6.2.tar.gz app]#tar xvf apr-util-1.6.0.tar.gz app]#tar xvf httpd-2.4.27.tar.bz2
编译安装依赖包
app]#cd apr-1.6.2apr-1.6.2]./configure --prefix=/app/apr <===指定目录apr-1.6.2]make & make installapr-util-1.6.0]#cd apr-util-1.6.0apr-util-1.6.0]#./configure --prefix=/app/apr-util --with-apr=/app/apr <===apr-util依赖apr包,所以要先安装apr包apr-util-1.6.0]#make & make install
编译安装httpd2.4
]#cd /app/httpd-2.4.27httpd-2.4.27]#./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/app/apr/ --with-apr-util=/app/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=preforkhttpd-2.4.27]#make & make install
创建apache用户
]#useradd -r -m -d /var/www -s /sbin/nologin apache
修改相关配置
1.配置文件
]#vim /app/httpd24/conf/httpd.conf <===需要修改的四项user apachegroup apacheDocumentroot /var/www/html<directory /var/www/html>
2.配置环境变量
]#vim /etc/profile.d/httpd24.shexport PATH=/app/httpd24/bin:$PATH
3.自定义启动脚本
]#scp /etc/init.d/httpd 192.168.32.10://etc/init.d/httpd24 <===参考httpd2.2的脚本。从其他主机拷贝一份,192.168.32.10为本机;]#vim /etc/init.d/httpd24 <===修改路径apachectl=/app/httpd24/bin/apachectlhttpd=${HTTPD-/app/httpd24/bin/httpd}pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}lockfile=${LOCKFILE-/var/lock/subsys/httpd}
4.添加开机启动,并启动httpd24
]#chkconfig�Cadd httpd24]#service httpd24 start]#ss -tan <===80端口已监听State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 64 :::873 :::* LISTEN 0 128 :::80 :::* LISTEN 0 32 *:21 *:* LISTEN 0 128 :::22 :::* LISTEN 0 128 *:22 *:* LISTEN 0 100 ::1:25 :::*
测试
]#echo httpd24 > /etc/www/html/index.html ]#service httpd24 reload
上面的方法编译了三次,比较繁琐,其实也可以只用一次编译。
方法二:
]#cp -av apr-1.6.2 /app/httpd-2.4.27/srclib/apr ]#cp -av apr-util-1.6.0 /app/httpd-2.4.27/srclib/apr-util <===2个依赖包解压缩后复制到指定目录并改名]#cd httpd-2.4.27/httpd-2.4.27]#./configure --prefix=/usr/local/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork <===注意这里要修改--with-included-apr
其余配置和第一种方法相同,这里就不在赘述。