LAMP(Linux- Apache-MySQL-PHP)網站架構是目前國際流行的Web框架,該框架包括:Linux操作系統,Apache網絡服務器,MySQL數據 庫,Perl、PHP或者Python編程語言,所有組成產品均是開源軟件,是國際上成熟的架構框架,很多流行的商業應用都是採取這個架構,和 Java/J2EE架構相比,LAMP具有Web資源豐富、輕量、快速開發等特點,微軟的.NET架構相比,LAMP具有通用、跨平臺、高性能、低價格的 優勢,因此LAMP無論是性能、質量還是價格都是企業搭建網站的首選平臺。
本節我們先來編譯安裝一下httpd,廢話不多說。
httpd-2.4.9需要較新版本的apr和apr-util,因此需要事先對其進行升級。升級方式有兩種,一種是通過源代碼編譯安裝,一種是直接升級rpm包。這裏選擇使用編譯源代碼的方式進行。
(1) 編譯安裝apr
# tar xf apr-1.5.0.tar.bz2 # cd apr-1.5.0 # ./configure --prefix=/usr/local/apr
注意:在編譯的時候你可能也會碰到和我一樣的錯誤
rm: cannot remove `libtoolT': No such file or directory config.status: executing default commands config.status: include/apr.h is unchanged config.status: include/arch/unix/apr_private.h is unchanged
我從網上找到的解決方法
vim configure
修改一下選項
$RM "$cfgfile"
爲
$RM -f "$cfgfile"
確認沒有問題就執行
# make && make install
(2) 編譯安裝apr-util
# tar xf apr-util-1.5.3.tar.bz2 # cd apr-util-1.5.3 # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
注意這裏apr指向的是剛剛編譯安裝的Apr路徑
確認沒有問題就執行
# make && make install
(3)編譯安裝httpd
httpd-2.4.9編譯過程也要依賴於pcre-devel軟件包,需要事先安裝。此軟件包系統光盤自帶,因此,找到並安裝即可。這裏我就不演示了。
下面我們就開始編譯安裝httpd-2.4.9了。
# tar xf httpd-2.4.9.tar.bz2 # cd httpd-2.4.9 # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
確認沒有問題就執行
# make && make install
(4)修改httpd的主配置文件,設置其Pid文件的路徑
編輯/etc/httpd24/httpd.conf,添加如下行即可:
[root@bogon ~]# vim /etc/httpd24/httpd.conf
PidFile "/var/run/httpd.pid"
這樣我們的httpd服務就已經安裝成功了,我們可以啓動下試試。
注意我們的安裝路徑,我們的執行腳本的位置是在/usr/local/apache/bin/下,因此我們先cd進去。
[root@bogon ~]# cd /usr/local/apache/bin/ [root@bogon bin]# ls ab apachectl apxs checkgid dbmmanage envvars envvars-std fcgistarter htcacheclean htdbm htdigest htpasswd httpd httxt2dbm logresolve rotatelogs
然後就可以執行了
注意,在執行的時候可以會有這樣的警告,這是我們可以去配置文件中修改ServerName這一項
[root@bogon bin]# vim /etc/httpd24/httpd.conf
啓用並修改成localhost
修改完之後我們的服務就可以啓用了
當命令輸錯時會有提示
按照提示可以知道我們可以通過以下命令打開
[root@bogon bin]# ./httpd -k start
現在我們可以通過windows上的瀏覽器來驗證下是否可以用了
沒錯,這樣我們的httpd就完成了。
(5)提供SysV服務腳本
如果你想讓httpd24可以向其它那些服務腳本一樣可以通過servcie service_name start|stop|restart|status等命令來使用的話只需要在/etc/rc.d/init.d/下建立相應的腳本即可。
[root@bogon bin]# vim /etc/rc.d/init.d/httpd24
#!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: Apache is a World Wide Web server. It is used to serve \ # HTML files and CGI. # processname: httpd # config: /etc/httpd/conf/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /var/run/httpd.pid # Source function library. . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG-"C"} # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile} -d 10 $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=$? echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else killproc -p ${pidfile} $httpd -HUP RETVAL=$? fi echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f ${pidfile} ] ; then stop start fi ;; reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" exit 1 esac exit $RETVAL
當然想要執行必須給此腳本賦予執行權限:
# chmod +x /etc/rc.d/init.d/httpd24
服務腳本創建好之後還需要加入服務列表,並啓用:
好了,那麼這樣我們的HTTP服務器就編譯安裝成功了!