RedHat 7 安裝HTTPD

甲骨文技術支援發表於2018-02-23
1.檢視作業系統版本

  1. [root@aws srclib]# cat /etc/redhat-release
  2. Red Hat Enterprise Linux Server release 7.4 (Maipo)
2.首先安裝apr,本例子是1.6.3版本

  1. wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
下載之後就是解壓

  1. tar -xzvf apr-1.6.3.tar.gz
進入apr目錄,執行configure命令,該命令本例就一個引數 ,設定安裝目錄

  1. cd /usr/local/src/apr-1.6.3
  2. ./configure --prefix=/usr/local/apr
配置好之後,執行make和make install

  1. make && make install
3.安裝apr-util,本例的版本是1.6.1

  1. wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2
在解壓的時候有可能遇到報錯:

  1. [root@aws src]# tar -jxvf apr-util-1.6.1.tar.bz2
  2. tar (child): bzip2: Cannot exec: No such file or directory
  3. tar (child): Error is not recoverable: exiting now
  4. tar: Child returned status 2
  5. tar: Error is not recoverable: exiting now
解決的辦法是:

  1. yum -y install bzip2
接下來和安裝apr一樣,先執行configure命令

  1. ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
然後執行安裝命令:

  1. make && make install
在安裝過程中可能遇到如下錯誤:

  1. pr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
  2. xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
  3.  #include <expat.h>
  4.                    ^
  5. compilation terminated.
  6. make[1]: *** [xml/apr_xml.lo] Error 1
  7. make[1]: Leaving directory `/usr/local/src/apr-util-1.6.1
解決辦法是安裝expat庫

  1. yum install expat-devel
4.安裝httpd

本例用的是2.4.29的版本

  1. wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz
同樣下載後就是解壓

  1. tar -xvzf httpd-2.4.29.tar.gz
進入目錄,執行configure命令

  1. ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most --with-included-apr
--enable-so的意思是啟用DSO,也就是把某些功能以模組(so)的形式展現出來
--enable-mods-shared=most表示以共享的方式安裝大多數功能模組,安裝後會在modules目錄下面看到。

如果遇到下面的報錯:

  1. checking for gcc option to accept ISO C99... -std=gnu99
  2. checking for pcre-config... false
  3. configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解決辦法是:

  1. yum install -y pcre pcre-devel
最後編譯和安裝

  1. make
  2. make install
以上兩個步驟都可以用命令echo $?來檢查是否執行成功。

在make的時候可能會報錯如下:

  1. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
  2. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'
  3. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate'
  4. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'
  5. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserFree'
  6. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetUserData'
  7. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
  8. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'
  9. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
  10. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
  11. collect2: error: ld returned 1 exit status
  12. make[2]: *** [htpasswd] Error 1
  13. make[2]: Leaving directory `/usr/local/src/httpd-2.4.29/support'
  14. make[1]: *** [all-recursive] Error 1
  15. make[1]: Leaving directory `/usr/local/src/httpd-2.4.29/support'
  16. make: *** [all-recursive] Error 1
解決辦法是:

  1. cp -rf /usr/local/src/apr-1.6.3 /usr/local/src/httpd-2.4.29/srclib/apr
  2. cp -rf /usr/local/src/apr-util-1.6.1 /usr/local/src/httpd-2.4.29/srclib/apr-util

5.至此httpd就安裝完成了

可以用下面的命令檢視安裝了那些模組:

  1. [root@aws srclib]# /usr/local/apache2.4/bin/apachectl -M
  2. Loaded Modules:
  3.  core_module (static)
  4.  so_module (static)
  5.  http_module (static)
  6.  mpm_event_module (static)
  7.  authn_file_module (shared)
  8.  authn_core_module (shared)
  9.  authz_host_module (shared)
  10.  authz_groupfile_module (shared)
  11.  authz_user_module (shared)
  12.  authz_core_module (shared)
  13.  access_compat_module (shared)
  14.  auth_basic_module (shared)
  15.  reqtimeout_module (shared)
  16.  filter_module (shared)
  17.  mime_module (shared)
  18.  log_config_module (shared)
  19.  env_module (shared)
  20.  headers_module (shared)
  21.  setenvif_module (shared)
  22.  version_module (shared)
  23.  unixd_module (shared)
  24.  status_module (shared)
  25.  autoindex_module (shared)
  26.  dir_module (shared)
  27.  alias_module (shared)
  28.  php5_module (shared)
其中帶有shared字樣的,表示該模組為動態共享模組;static為靜態模組。

動態和靜態的區別是靜態模組直接和主程式(/usr/local/apache2.4/bin/httpd)繫結在一起,我們是看不到的;而動態的模組都是一個個獨立存在的檔案,也就是modules目錄下的.so檔案

6.配置httpd支援php

a.編輯httpd.conf檔案(/usr/local/apache2.4/conf/httpd.conf),搜尋ServerName,把ServerName 前面的#去掉

b.找到如下內容
  1. <Directory />
  2.     AllowOverride none
  3.     Require all denied
  4. </Directory>
  5. 修改為
  6. <Directory />
  7.     AllowOverride none
  8.     Require all granted
  9. </Directory>
c.再搜尋下面這一行

  1. AddType application/x-gzip .gz .tgz
  2. 在上面這行下面新增
  3. AddType application/x-httpd-php .php
d.找到下面這一段

  1. <IfModule dir_module>
  2.    DirectoryIndex index.html
  3. </IfModule>
  4. 修改為
  5. <IfModule dir_module>
  6.    DirectoryIndex index.html index.php
  7. </IfModule>
7.啟動之前檢查配置檔案是否正確,出現Syntax OK,說明沒有問題

  1. [root@aws php-5.6.30]# /usr/local/apache2.4/bin/apachectl -t
  2. Syntax OK
8.啟動httpd的命令如下:

  1. /usr/local/apache2.4/bin/apachectl start
9.檢視是否啟動的命令如下:

  1. [root@aws srclib]# netstat -lnp | grep httpd
  2. tcp6 0 0 :::80 :::* LISTEN 30298/httpd
10.做個簡單測試,出現It works說明測試成功

  1. [root@aws srclib]# curl localhost
  2. <html><body><h1>It works!</h1></body></html>

歡迎訪問我的另一篇文章,RedHat 7 安裝PHP

http://blog.itpub.net/20893244/viewspace-2151185/





來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20893244/viewspace-2151184/,如需轉載,請註明出處,否則將追究法律責任。

相關文章