首頁  >  文章  >  運維  >  linux怎麼安裝apache伺服器

linux怎麼安裝apache伺服器

步履不停
步履不停原創
2019-06-28 15:24:1113109瀏覽

linux怎麼安裝apache伺服器

壓縮套件安裝方式

#1、下載httpd-2.4.29.tar.gz 

2、上傳到伺服器/usr/local/software

tar -zxvf httpd-2.4.29.tar.gz
./configure --prefix=/usr/local/apache2/ # 设置apache安装目录

若沒有安裝過Apr,會報錯:

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

3、接下來安裝apr,先下載apr- 1.6.3.tar.gz 

4、上傳到伺服器/usr/local/software

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

又會報錯:

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

5、下載apr-util-1.6 .1.tar.gz 

6、上傳到伺服器/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

此時還會報錯:

xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录
 #include <expat.h>
                   ^
编译中断。
make: *** [xml/apr_xml.lo] 错误 1

7、猜測是可能缺少expat的開發庫

yum install expat-devel # 中间会让你输入y
./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr
make # 成功!
make install

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

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

依舊報錯,不少人到這裡可能已經崩潰了,但這個錯誤跟前面遇到的類似

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、上傳到伺服器/usr/local/software

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

又報錯,我保證這是最後一次了

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 環境

yum install -y gcc gcc-c++
# 错了那么多次,别忘了现在的位置,接下来还是要安装pcre
./configure
make
make install

11、好了,繞了一大圈,接下來還是要安裝apache

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

好慘!最後一步又報錯:

/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode&#39;  
/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler&#39;  
/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_ParserCre
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] 错误 1
make[2]: Leaving directory `/usr/local/software/apache/support&#39;
make[1]: *** [all-recursive] 错误 1
make[1]: Leaving directory `/usr/local/software/apache/support&#39;

這種報錯沒見過,果斷網上搜索一番,答案即是:apr版本太高; 

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

13、上傳伺服器/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.重複步驟11,唯一不同的地方就是現在配置指定的是: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时间会比较长
make install

完美結尾:

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&#39;

15、進入設定檔位置:/usr/local/apache2/conf

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

16、啟動apache

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

關閉防火牆,在瀏覽器網址列輸入伺服器的ip就會出現網頁:It works! 

#17、關閉apache

ps -ef|grep apache
/usr/local/apache2/bin/apachectl stop
# 或者
/usr/local/apache2//bin/httpd -k stop
# 没错,bin前面就是//

這種原檔案安裝的方式太複雜,其實安裝apache服務還有另一種方式,不知道跟我前面這種安裝有沒有衝突,今天也試試看。

yum來源安裝方式

1、yum來源安裝(需要連網下載)

首先关闭apache服务
yum install httpd # 中间过程中输入: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,我進入後備份設定檔先,修改的地方跟之前不一樣,在95行,僅供參考

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

3、啟動服務

systemctl start httpd.service

在瀏覽器輸入ip,出現apache預置的html,完美! ! !

linux怎麼安裝apache伺服器4、關閉服務

systemctl stop httpd.service

5、我再次去啟動第一種方式安裝的httpd

/usr/local/apache2/bin/apachectl start

刷新瀏覽器赫然出現:It works!,說明兩種安裝方式沒有衝突哈。 

更多Apache的相關技術文章,請造訪Apache教學欄位進行學習!

以上是linux怎麼安裝apache伺服器的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
上一篇:apache怎麼卸載下一篇:apache怎麼卸載