1. 程式人生 > >在centos6編譯安裝httpd-2.4方法一

在centos6編譯安裝httpd-2.4方法一

編譯安裝httpd-2.4

安裝httpd-2.4
依賴於apr-1.4+, apr-util-1.4+, [apr-iconv]
apr: apache portable runtime,解決跨平臺實現
CentOS 6:默認:apr-1.3.9, apr-util-1.3.9
安裝前準備開發包:
開發環境包組:
Development Tools,Server
相關包:pcre-devel,openssl-devel expat-devel
下載源代碼並解壓縮:
httpd-2.4.27.tar.bz2
apr-1.6.2.tar.bz2
apr-util-1.6.0.tar.bz2
第一步:先安裝所需要的包。(工作中不要裝包組,挑一些去裝)
yum groupinstall "development tools"
yum install openssl-devel pcre-devel expat-devel
[root@centos6 apr-1.6.3]# yum install libtool
[root@centos6 ~]# mkdir httpd2.4
[root@centos6 ~]# cd httpd2.4/
把源代碼傳到裏面;
[root@centos6 httpd2.4]#rz
然後解壓縮。
tar xvf apr-1.6.3.tar.bz2
tar xvf apr-util-1.6.1.tar.bz2
tar xvf httpd-2.4.29.tar.bz2
編譯httpd之前要先編譯APR
第二步:現在我們先去編譯APR ( apr-1.6.3)
[root@centos6 httpd2.4]# cd apr-1.6.3
[root@centos6 apr-1.6.3]# ls
apr-config.in buildconf dso libapr.rc NOTICE support
apr.dep build.conf emacs-mode LICENSE NWGNUmakefile tables
apr.dsp build-outputs.mk encoding locks passwd test
apr.dsw CHANGES file_io Makefile.in poll threadproc
apr.mak CMakeLists.txt helpers Makefile.win random time
apr.pc.in config.layout include memory README tools
apr.spec configure libapr.dep misc README.cmake user
atomic configure.in libapr.dsp mmap shmem
build docs libapr.mak network_io strings
[root@centos6 apr-1.6.3]# ./configure --prefix=/app/apr (開始編譯)
[root@centos6 apr-1.6.3]#make -j 4 && make install
[root@centos6 apr-1.6.3]# ls /app
apr
[root@centos6 apr-1.6.3]# cd ..
[root@centos6 httpd2.4]# ls
apr-1.6.3 apr-util-1.6.1 httpd-2.4.29
apr-1.6.3.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.29.tar.bz2
[root@centos6 httpd2.4]# cd apr-util-1.6.1
[root@centos6 apr-util-1.6.1]# ls
aprutil.dep build.conf docs LICENSE redis
aprutil.dsp build-outputs.mk encoding Makefile.in renames_pending
aprutil.dsw CHANGES export_vars.sh.in Makefile.win strmatch
aprutil.mak CMakeLists.txt hooks memcache test
apr-util.pc.in config.layout include misc uri
apr-util.spec configure ldap NOTICE xlate
apu-config.in configure.in libaprutil.dep NWGNUmakefile xml
buckets crypto libaprutil.dsp README
build dbd libaprutil.mak README.cmake
buildconf dbm libaprutil.rc README.FREETDS
[root@centos6 apr-util-1.6.1]# ./configure --prefix=/app/apr-util --with-apr=/app/apr
[root@centos6 apr-1.6.3]#make -j 4 && make install

第三部:編譯安裝httpd2.4
[root@centos6 apr-util-1.6.1]# cd ..
[root@centos6 httpd2.4]# cd httpd-2.4.29
[root@centos6 httpd2.4]#./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=prefork
[root@centos6 httpd-2.4.29]# make -j 4 && make install

[root@centos6 httpd-2.4.29]# cd /app
[root@centos6 app]# ls
apr apr-ut httpd24

第四步:環境變量。
[root@centos6 httpd24]# cd bin
[root@centos6 bin]# ls
ab apxs dbmmanage envvars-std htcacheclean htdigest httpd logresolve
apachectl checkgid envvars fcgistarter htdbm htpasswd httxt2dbm rotatelogs

[root@centos6 bin]# echo ‘PATH=/app/httpd24/bin/:$PATH‘ > /etc/profile.d/httpd24.sh
[root@centos6 bin]# . /etc/profile.d/httpd24.sh
[root@centos6 bin]# apachectl start
第五步:用戶和組
(這裏註意:如果是最小化安裝,apache 用戶是沒有的,要手工進行創建。
[root@centos6 bin]# getent passwd apache
apache:x:48:48:Apache:/var/www:/sbin/nologin
創建的方法是:
useradd -r -s /sbin/nologin apache
[root@centos6 bin]#ss -ntlp

第六部:配置文件
[root@centos6 bin]# cd /root/httpd2.4/
[root@centos6 httpd2.4]# ls
apr-1.6.3 apr-util-1.6.1 httpd-2.4.29
apr-1.6.3.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.29.tar.bz2
[root@centos6 httpd2.4]# cd httpd-2.4.29/
[root@centos6 httpd-2.4.29]# ls
apr-1.6.3 apr-util-1.6.1 httpd-2.4.29
apr-1.6.3.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.29.tar.bz2
[root@centos6 httpd2.4]# cd httpd-2.4.29/
[root@centos6 httpd-2.4.29]# cd /app/httpd24/conf/
[root@centos6 conf]# ls
extra httpd.conf magic mime.types original
[root@centos6 conf]# vim /app/httpd24/conf/httpd.conf
技術分享圖片
user apache
group apache

[root@centos6 conf]# apachectl restart (重啟服務)
[root@centos6 conf]# ps aux
技術分享圖片

現在就可以試試啦:
[root@centos7 ~]# curl 192.168.10.107
<html><body><h1>It works!</h1></body></html>
它的路徑放在:
技術分享圖片
[root@centos6 ~]# cd /app/httpd24/
[root@centos6 httpd24]# ls
bin build cgi-bin conf error htdocs icons include logs man manual modules
[root@centos6 httpd24]# cd htdocs
[root@centos6 htdocs]# ls
index.html

第七步:開機腳本。

設為開機啟動:
[root@centos6 conf]# echo "/app/httpd24/bin/apachectl start" >> /etc/rc.d/rc.local
開機重啟。
最好寫腳本:
cp /etc/init.d/httpd /etc/init.d/httpd24
vim /etc/init.d/httpd24
apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/httpd}
pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
技術分享圖片
[root@centos6 ~]# ll /etc/init.d/httpd24
讀寫執行的權限。
chkconfig --add httpd24
chkconfig httpd24 on
service httpd24 start
reboot

vim /etc/rc.d/rc.local

/app/httpd24/bin/apachectl start 就可以刪啦。

在centos6編譯安裝httpd-2.4方法一