溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Linux系統(tǒng)搭建Apache服務(wù)器的步驟是什么

發(fā)布時(shí)間:2022-01-26 11:32:14 來(lái)源:億速云 閱讀:203 作者:柒染 欄目:開(kāi)發(fā)技術(shù)

Linux系統(tǒng)搭建Apache服務(wù)器的步驟是什么,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

apache服務(wù)器簡(jiǎn)介:

  • Apache是目前世界上使用最廣泛的一種web server,它以跨平臺(tái),高效和穩(wěn)定而聞名。

  • Apache缺點(diǎn)是變得越來(lái)越重,被普遍認(rèn)為是重量級(jí)的web server。(Apache主要采用的是基于進(jìn)程的Prefork模式(還有基于線程的Worker模式),也就是,對(duì)于每個(gè)請(qǐng)求會(huì)用一個(gè)進(jìn)程去進(jìn)行服務(wù),進(jìn)程非常占資源,當(dāng)并發(fā)量大的時(shí)候,就需要等額的進(jìn)程,導(dǎo)致的是高內(nèi)存占用和CPU占用,這就是所謂的“重量級(jí)”。

  • Apache是基于模塊化設(shè)計(jì)的,總體上看起來(lái)代碼的可讀性高于php代碼,它的核心代碼并不多,大多數(shù)的功能都被分割到各種模塊中,各個(gè)模塊在系統(tǒng)啟動(dòng)時(shí)按需載入。

Linux系統(tǒng)搭建apache服務(wù)器詳細(xì)步驟:

壓縮包安裝方式

1、下載httpd-2.4.29.tar.gz

2、上傳到服務(wù)器/usr/local/software

 tar -zxvf httpd-2.4.29.tar.gz``./configure --prefix=/usr/local/apache2/ # 設(shè)置apache安裝目錄

若沒(méi)有安裝過(guò)Apr,會(huì)報(bào)錯(cuò):

 checking ``for` `APR... no``configure: error: APR not found. Please read the documentation.

3、接下來(lái)安裝apr,首先下載apr-1.6.3.tar.gz

4、上傳到服務(wù)器/usr/local/software

 tar -zxvf apr-1.6.3.tar.gz``cd apr-1.6.3``.configure``make``make install

又會(huì)報(bào)錯(cuò):

 checking ``for` `APR-util... no``configure: error: APR-util not found. Please read the documentation.

5、下載apr-util-1.6.1.tar.gz

6、上傳到服務(wù)器/usr/local/software

 tar -zxvf apr-util-1.6.1.tar.gz``cd apr-util-1.6.1``./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr

此時(shí)還會(huì)報(bào)錯(cuò):

 xml/apr_xml.c:35:19: 致命錯(cuò)誤:expat.h:沒(méi)有那個(gè)文件或目錄`` ``#``include` ```          ``^``編譯中斷。``make: *** [xml/apr_xml.lo] 錯(cuò)誤 1

7、猜測(cè)是可能缺expat的開(kāi)發(fā)庫(kù)

 yum install expat-devel # 中間會(huì)讓你輸入y``./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr``make # 成功!``make install

8、此時(shí)再回去安裝apache,不僅要指定apr的路徑,還要指定apr-util的路徑

 ./configure --prefix=/usr/local/apache2/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/

依舊報(bào)錯(cuò),不少人到這里可能已經(jīng)崩潰了,但這個(gè)錯(cuò)誤跟前面遇到的類似

 checking ``for` `pcre-config... false``configure: error: pcre-config ``for` `libpcre not found. PCRE is required ``and` `available from http:``//pcre.org/

9、下載pcre-8.41.tar.gz

10、上傳到服務(wù)器/usr/local/software

 tar -zxvf pcre-8.41.tar.gz``./configure

又再次報(bào)錯(cuò),我保證這是最后一次了

 checking windows.h usability... no``checking windows.h presence... no``checking ``for` `windows.h... no``configure: error: You need a C++ compiler ``for` `C++ support.

10、安裝c++環(huán)境

 yum install -y gcc gcc-c++``# 錯(cuò)了那么多次,別忘了現(xiàn)在的位置,接下來(lái)還是要安裝pcre``./configure``make``make install

11、好了,繞了一大圈,接下來(lái)還是要安裝apache

 cd ..``cd apache``./configure --prefix=/usr/local/apache2/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/``make``make install

好慘??!最后一步又報(bào)錯(cuò):

 /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_ParserCre``collect2: error: ld returned 1 ``exit` `status``make[2]: *** [htpasswd] 錯(cuò)誤 1``make[2]: Leaving directory `/usr/local/software/apache/support'``make[1]: *** [all-recursive] 錯(cuò)誤 1``make[1]: Leaving directory `/usr/local/software/apache/support'

這種報(bào)錯(cuò)沒(méi)見(jiàn)過(guò),果斷網(wǎng)上搜索一番,答案即是:apr版本太高;

12、于是我下載了apr-util-1.5 http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz

13、上傳到服務(wù)器/usr/local/software

 tar -zxvf apr-util-1.5.2.tar.gz``cd apr-util-1.5.2``./configure --prefix=/usr/local/apr-util-1.5/ --with-apr=/usr/local/apr``make``make install

14、重復(fù)步驟11,唯一不同的地方就是現(xiàn)在配置指定的是:apr-util-1.5,這很重要!??!

 cd ..``cd apache``./configure --prefix=/usr/local/apache2/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util-1.5/``make # make時(shí)間會(huì)比較長(zhǎng)``make install

完美結(jié)尾:

 Installing configuration files``mkdir` `/usr/local/apache2/conf``mkdir` `/usr/local/apache2/conf/extra``mkdir` `/usr/local/apache2/conf/original``mkdir` `/usr/local/apache2/conf/original/extra``Installing HTML documents``mkdir` `/usr/local/apache2/htdocs``Installing error documents``mkdir` `/usr/local/apache2/error``Installing icons``mkdir` `/usr/local/apache2/icons``mkdir` `/usr/local/apache2/logs``Installing CGIs``mkdir` `/usr/local/apache2/cgi-bin``Installing header files``mkdir` `/usr/local/apache2/``include``Installing build system files``mkdir` `/usr/local/apache2/build``Installing man pages ``and` `online manual``mkdir` `/usr/local/apache2/man``mkdir` `/usr/local/apache2/man/man1``mkdir` `/usr/local/apache2/man/man8``mkdir` `/usr/local/apache2/manual``make[1]: Leaving directory `/usr/local/software/apache'

15、進(jìn)入配置文件位置:/usr/local/apache2/conf

 cp httpd.conf httpd.conf.bak  # 備份配置文件``vim httpd.conf``# 放掉191行的注釋,修改為:``ServerName [你的IP]:80``:wq

16、啟動(dòng)apache

 /usr/local/apache2/bin/apachectl start``# 或者``/usr/local/apache2``//bin/httpd -k start

關(guān)閉防火墻,在瀏覽器地址欄中輸入服務(wù)器的ip就會(huì)出現(xiàn)網(wǎng)頁(yè):It works!

17、關(guān)閉apache

 ps -ef|grep apache``/usr/local/apache2/bin/apachectl stop``# 或者``/usr/local/apache2``//bin/httpd -k stop``# 沒(méi)錯(cuò),bin前面就是``//

這種原文件安裝的方式太過(guò)復(fù)雜,其實(shí)安裝apache服務(wù)還有另一種方式,不知道跟我前面這種安裝有沒(méi)有沖突,今天也一并試一試。

yum源安裝方式

1、yum源安裝(需要聯(lián)網(wǎng)下載)

 首先關(guān)閉apache服務(wù)``yum install httpd # 中間過(guò)程中輸入:y

Result:

作為依賴被安裝:

  ``apr.x86_64 0:1.4.8-3.el7_4.1   `` ``apr-util.x86_64 0:1.5.2-6.el7    `` ``httpd-tools.x86_64 0:2.4.6-67.el7.centos.6   `` ``mailcap.noarch 0:2.1.41-2.el7    ``完畢!

2、yum的安裝位置在:/etc/httpd/conf,我進(jìn)入后備份配置文件先,修改的地方跟之前不一樣,在95行,僅供參考

 cd /etc/httpd/conf``cp httpd.conf httpd.conf.bak``# 放掉95行的注釋,修改為:``ServerName [你的IP]:80``:wq

3、啟動(dòng)服務(wù)

 systemctl start httpd.service

在瀏覽器輸入ip,出現(xiàn)apache預(yù)置的html,完美!??!

Linux系統(tǒng)搭建Apache服務(wù)器的步驟是什么4、關(guān)閉服務(wù)

 systemctl stop httpd.service

5、我再次去啟動(dòng)第一種方式安裝的httpd

 /usr/local/apache2/bin/apachectl start

刷新瀏覽器赫然出現(xiàn):It works!,說(shuō)明兩種安裝方式?jīng)]有沖突哈。

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI