1、centos6中源碼編譯安裝httpd-2.2.34
0 準備工作
查看相同的軟件
rpm -qa "httpd*"
yum remove httpd
1 安裝開發包組
yum groupinstall "Development tools"
2 下載源碼并解包
tar xvf httpd-2.2.34.tar.bz2
cd /usr/local/src/httpd-2.2.34
3 看說明
cat README
cat INSTALL
4 生成Makefile
cd /usr/local/src/httpd-2.2.34
./configure --help
./configure --prefix=/app/httpd22/ --sysconfdir=/etc/httpd22/ --enable-ssl
echo $? ---判斷上一條命令是否執行成功
yum install openssl-devel ---需要安裝這個軟件包
./configure --prefix=/app/httpd22/ --sysconfdir=/etc/httpd22/ --enable-ssl ---再執行一次。沒有錯誤
5
make - j 4 && make install ---4顆cpu并行。讓安裝的速度快一點
6 軟件配置
準備環境變量
echo 'export PATH=$PATH: /app/httpd22/bin'> /etc/profile.d/httpd22.sh ---此處需要注意,不能用雙引號和不加符號,否則$PATH會展開
. /etc/profile.d/httpd22.sh ---讓文件生效,也可以用source
echo $PATH
apachctl start ---這樣在哪個目錄下都可以運行apachectl,不用每次都得進入當前目錄/app/httpd22/bin
ss -ntl 80端口打開即成功
http://本機IP/
vim /app/httpd22/htdocs/index.html
添加man幫助的路徑到配置文件
vim /etc/man.config
加一行
MANPATH /app/httpd22/man
2、centos7中源碼編譯安裝httpd-2.4.27
[root@centos7 test]#rpm -qa "httpd*" ---查看之前有沒有安裝過http,避免干擾
httpd-tools-2.4.6-45.el7.centos.x86_64
httpd-2.4.6-45.el7.centos.x86_64
[root@centos7 test]#yum remove httpd httpd-tools-2.4.6-45.el7.centos.x86_64
[root@centos7 test]#yum groupinstall " Development Tools" ---安裝開發包組
Complete!
[root@centos7 test]#cd /usr/local/src/
[root@centos7 src]#ls
[root@centos7 src]#rz
[root@centos7 src]#ls
httpd-2.4.27.tar.bz2
[root@centos7 src]#tar -xvf httpd-2.4.27.tar.bz2 ---解壓文件
[root@centos7 src]#ls
httpd-2.4.27 httpd-2.4.27.tar.bz2
[root@centos7 src]#cd httpd-2.4.27/
[root@centos7 httpd-2.4.27]#ls
ABOUT_APACHE CMakeLists.txt INSTALL NWGNUmakefile
acinclude.m4 config.layout InstallBin.dsp os
Apache-apr2.dsw configure LAYOUT README
Apache.dsw configure.in libhttpd.dep README.cmake
apache_probes.d docs libhttpd.dsp README.platforms
ap.d emacs-style libhttpd.mak ROADMAP
build httpd.dep LICENSE server
BuildAll.dsp httpd.dsp Makefile.in srclib
BuildBin.dsp httpd.mak Makefile.win support
buildconf httpd.spec modules test
CHANGES include NOTICE VERSIONING
[root@centos7 httpd-2.4.27]#cat README ---此文件介紹了apache http服務是干什么的
Apache HTTP Server
What is it?
-----------
[root@centos7 httpd-2.4.27]#cat INSTALL
APACHE INSTALLATION OVERVIEW
Quick Start - Unix
------------------
For complete installation documentation, see [ht]docs/manual/install.html or
http://httpd.apache.org/docs/2.4/install.html ---介紹了安裝過程。可以分為四步
$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start
[root@centos7 httpd-2.4.27]#./configure --help ---運行configure腳本之前,先看一下幫助。里面告訴了一些用法,怎么制定路徑,制定一些特性。哪些需要安裝,哪些不需要安裝
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local/apache2]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
[root@centos7 httpd-2.4.27]#./configure --prefix=/app/httpd24 ---運行configure腳本生成makefile文件,這里只規定安裝目錄就可以,不用指定其他的目錄。這樣不好管理,特性暫時也不加了,還沒有學習到
[root@centos7 httpd-2.4.27]#yum install apr-devel.x86_64
[root@centos7 httpd-2.4.27]#./configure --prefix=/app/httpd24
[root@centos7 httpd-2.4.27]#yum install apr-util-devel.x86_64
[root@centos7 httpd-2.4.27]#./configure --prefix=/app/httpd24
[root@centos7 httpd-2.4.27]#yum install pcre-devel.x86_64
[root@centos7 httpd-2.4.27]#./configure --prefix=/app/httpd24 ---前面一直在排錯的過程,運行腳本時發現有好多包都沒有裝。會提示錯誤,需要安裝。一般都是與開發有關的包就可以
[root@centos7 httpd-2.4.27]#make -j 4 && make install&&echo -e '\a' ---制作和安裝可以合成一步進行,最后加上打印聲音,可以運行完之后發出聲音,注意此步驟是在和configure腳本在同一目錄下進行的
[root@centos7 httpd-2.4.27]#cd /app
[root@centos7 app]#ls
a.out hello hello.c Hello.class Hello.java httpd24 music music.sh test
[root@centos7 app]#cd httpd24/
[root@centos7 httpd24]#ls
bin cgi-bin error icons logs manual
build conf htdocs include man modules
[root@centos7 httpd24]#cd bin
[root@centos7 bin]#ls
ab checkgid envvars-std htdbm httpd rotatelogs
apachectl dbmmanage fcgistarter htdigest httxt2dbm
apxs envvars htcacheclean htpasswd logresolve
[root@centos7 bin]#echo 'export PATH=/app/httpd24/bin:$PATH'>/etc/profile.d/httpd24.sh---設置變量,這樣不用每次啟動apachectl時進入該目錄才能執行
[root@centos7 bin]#source /etc/profile.d/httpd24.sh
[root@centos7 bin]#echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/app:/root/bin:/app:/app/test:/app/test/7.31:/root/bin:/app:/app/test:/app/httpd24/bin
[root@centos7 bin]#apachectl start
[root@centos7 bin]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::* ---對應的端口已經打開
LISTEN 0 32 :::21 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
[root@centos7 httpd24]#cd htdocs
[root@centos7 htdocs]#ls
index.html
[root@centos7 htdocs]#vim index.html ---修改一下網頁的頁面
1 <html><body><h1>welcome to magedu.com!</h1></body></html>
[root@centos7 man]#vim /etc/man_db.conf ---在man幫助的配置文件中增加次程序的路徑。
# every automatically generated MANPATH includes these fields
#
#MANDATORY_MANPATH /usr/src/pvm3/man
#
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /app/httpd24/man
總結:需要注意的是:定義變量echo 'export PATH=/app/httpd24/bin:$PATH'>/etc/profile.d/httpd24.sh時一定要將/app/httpd24/bin寫到前面,先生效,因為系統里自帶一個apachectl,如果$PATH寫到前面,會讓/usr/sbin/apachectl這個路徑先生效,這一樣啟動的時候就是系統自帶的,而不是元碼編譯安裝的。
3、在centos6和centos7上一鍵源碼編譯安裝apache http服務的腳本
#!/bin/bash
yum -y -q remove httpd*&>/dev/null
echo "httpd* is removed"
yum -y -q groupinstall "Development Tools"&>/dev/null
echo "Development Tools is install"
release=`egrep -o " [0-9]" /etc/centos-release|tr -d " " `
[ "$release" -eq 6 ]&&{ cd httpd-2.2.34;./configure--prefix=/app/httpd22&>/dev/null;make && make install&>/dev/null; }
[ "$release" -eq 7 ]&&{ yum -y -q install "apr-devel.x86_64" "apr-util-devel.x86_64" "pcre-devel.x86_64"&>/dev/null;cd httpd-2.4.27;./configure --prefix=/app/httpd24&>/dev/null;make&>/dev/null && make install&>/dev/null; }
echo "apachectl is install"
unset release