Linux中如何安裝Apache伺服器
由於學習的需要,所有手動安裝了一下Apache源碼包,安裝過程中的問題千奇百怪,但是如果弄清楚了問題出在哪裡,那麼也不是太難。如果有學習者出現安裝中的問題,可仔細閱讀該教程。 首先下載httpd軟體包(http://httpd.apache.org/download.cgi#apache24)。 由於本人是在虛擬機器中安裝的CentOs7.0,所以我們還需要下載一個軟體用來將下載在Windows中的包檔案放置在Linux中。(:http://winscp.net/eng/docs/lang:chs) 點擊安裝WinSCP,安裝成功後可出現該介面::輸入虛擬機器的IP地址,使用者名稱和密碼,點擊登入即可。找到下載的包檔案,可將包檔案拖拽進Linux檔案夾中,注意:需要將下載的httpd包檔案放置在/usr/local/src檔案目錄下,該目錄常用來放置各種源碼包。 下面我們登入到Linux中,到達src目錄下(cd /usr/local/src),對放置的httpd包檔案進行解壓 #tar -zxvf httpd包檔案(注意這裡可能會有一個小插曲,當你解壓時可能會出現: gzip: stdin: not in gzip formattar: Child returned status 1tar: Error exit delayed from previous errors 這樣的錯誤,原因很簡單由於壓縮包沒有用gzip格式壓縮的,所有解壓時可以去掉'z',這樣即可成功解壓): #cd httpd檔案夾 #cd ./configure --prefix=/usr/local/apache 這時出現了下面的問題: [root@localhost httpd-2.4.17]# ./configure --prefix=/usr/local/apache2 checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu configure: configure: Configuring Apache Portable Runtime library... configure: checking for APR... no configure: error: APR not found. Please read the documentation. 從最後一行的配置資訊中可以得知:APR沒有找到,那麼APR是什麼呢? 注意:大家不要將APR與ARP兩者混淆,前者是(Apache portable Run-time libraries,Apache可移植運行庫,其主要作用是為上層的應用程式提供一個可以跨越多作業系統平台使用的底層支援介面庫),而後者是(Address Resolution Protocol,位址解析通訊協定)。 好了,下面我們就可以去下載APR包了,但要告訴大家,APR還依賴於軟體包APR-util,所有我們還需要下載APR-util :(http://apr.apache.org/) 我們依然利用文章開頭所講的方法,將其放到/usr/local/src目錄下面。下面進行解壓安裝: #cd /usr/local/src #tar -xvf apr包檔案 #cd apr檔案夾 #cd ./configure --prefix=/usr/local/apr-util 但出現了下面的配置問題:從配置資訊中可以發現:我們需要安裝Gcc編譯器 我們可以使用線上安裝gcc #yum install gcc #yum install gcc-c++(這個一定要安裝,如果未安裝,下面的安裝中還會要求安裝該軟體包) 安裝完成後即可重新安裝APR-util,APR,依舊按照先前的方法進行安裝,即可安裝通過。 當我們安裝httpd包檔案時,發現在安裝中出現了: checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking how to run the C preprocessor... gcc -E checking for gcc option to accept ISO C99... -std=gnu99 checking for pcre-config... false configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ 從配置資訊中可知:我們還需要安裝PCRE包檔案,其實安裝到這裡我想大家都是很崩潰的,心想怎麼這麼多東西要安裝,這裡我們就要說一下Linux中關於軟體包的依賴性,如果以安裝Apache伺服器為例的話,就是:httpd包檔案-->PCRE-->ARP-->APR-util-->GCC 所有如果我們選擇源碼安裝的話,就必須要一步一步認真安裝。 我們可以到網上找到配置資訊中的PCRE(主要用於字串的模式分割、匹配、尋找及替換操作) :http://download.chinaunix.net/download/0008000/7913.shtml #unzip pcre包檔案 #cd pcre檔案夾 #configure --prefix=/usr/local/pcre--with-apr=/usr/local/apr/bin/apr-1-config #make #make install 等我們安裝成功之後就可以再次安裝httpd安裝包了,接下來大家可以放心,後面不會再有其他依賴的安裝包軟體了,我們還是按照先前的方法: #cd httpd包檔案 #cd./configure--prefix=/usr/local/apache--with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util #make #make install 好了,終於安裝成功了,那麼我們開啟Apache服務,但在開啟之前我們要修改一個小地方: #cd /usr/local/apache/conf #vi httpd.conf 找到#ServerName www.example.com:80 在下面添加ServerName 192.168.9.122:80 儲存退出即可 最後我們來啟動一下:接下來我們可在瀏覽器中查看:出現It Works !即可說明你的Apache伺服器安裝成功。