十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
這篇文章給大家介紹RedHat 7怎樣安裝HTTPD,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
成都創(chuàng)新互聯(lián)公司從2013年成立,先為分宜等服務(wù)建站,分宜等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為分宜企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
1.查看操作系統(tǒng)版本
[root@aws srclib]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.4 (Maipo)
2.首先安裝apr,本例子是1.6.3版本
wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
下載之后就是解壓
tar -xzvf apr-1.6.3.tar.gz
進入apr目錄,執(zhí)行configure命令,該命令本例就一個參數(shù) ,設(shè)置安裝目錄
cd /usr/local/src/apr-1.6.3
./configure --prefix=/usr/local/apr
配置好之后,執(zhí)行make和make install
make && make install
3.安裝apr-util,本例的版本是1.6.1
wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2
在解壓的時候有可能遇到報錯:
[root@aws src]# tar -jxvf apr-util-1.6.1.tar.bz2
tar (child): bzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
解決的辦法是:
yum -y install bzip2
接下來和安裝apr一樣,先運行configure命令
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
然后執(zhí)行安裝命令:
make && make install
在安裝過程中可能遇到如下錯誤:
pr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
#include
^
compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/usr/local/src/apr-util-1.6.1
解決辦法是安裝expat庫
yum install expat-devel
4.安裝httpd
本例用的是2.4.29的版本
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz
同樣下載后就是解壓
tar -xvzf httpd-2.4.29.tar.gz
進入目錄,執(zhí)行configure命令
./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)的形式展現(xiàn)出來
--enable-mods-shared=most表示以共享的方式安裝大多數(shù)功能模塊,安裝后會在modules目錄下面看到。
如果遇到下面的報錯:
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/
解決辦法是:
yum install -y pcre pcre-devel
最后編譯和安裝
make
make install
以上兩個步驟都可以用命令echo $?來檢查是否執(zhí)行成功。
在make的時候可能會報錯如下:
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserFree'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetUserData'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] Error 1
make[2]: Leaving directory `/usr/local/src/httpd-2.4.29/support'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/httpd-2.4.29/support'
make: *** [all-recursive] Error 1
解決辦法是:
cp -rf /usr/local/src/apr-1.6.3 /usr/local/src/httpd-2.4.29/srclib/apr
cp -rf /usr/local/src/apr-util-1.6.1 /usr/local/src/httpd-2.4.29/srclib/apr-util
5.至此httpd就安裝完成了
可以用下面的命令查看安裝了那些模塊:
[root@aws srclib]# /usr/local/apache2.4/bin/apachectl -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_event_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
php5_module (shared)
其中帶有shared字樣的,表示該模塊為動態(tài)共享模塊;static為靜態(tài)模塊。
動態(tài)和靜態(tài)的區(qū)別是靜態(tài)模塊直接和主程序(/usr/local/apache2.4/bin/httpd)綁定在一起,我們是看不到的;而動態(tài)的模塊都是一個個獨立存在的文件,也就是modules目錄下的.so文件
6.配置httpd支持php
a.編輯httpd.conf文件(/usr/local/apache2.4/conf/httpd.conf),搜索ServerName,把ServerName www.example.com:80前面的#去掉
b.找到如下內(nèi)容
AllowOverride none
Require all denied
修改為
AllowOverride none
Require all granted
c.再搜索下面這一行
AddType application/x-gzip .gz .tgz
在上面這行下面添加
AddType application/x-httpd-php .php
d.找到下面這一段
DirectoryIndex index.html
修改為
DirectoryIndex index.html index.php
7.啟動之前檢查配置文件是否正確,出現(xiàn)Syntax OK,說明沒有問題
[root@aws php-5.6.30]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
8.啟動httpd的命令如下:
/usr/local/apache2.4/bin/apachectl start
9.查看是否啟動的命令如下:
[root@aws srclib]# netstat -lnp | grep httpd
tcp6 0 0 :::80 :::* LISTEN 30298/httpd
10.做個簡單測試,出現(xiàn)It works說明測試成功
[root@aws srclib]# curl localhost
關(guān)于RedHat 7怎樣安裝HTTPD就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。