天天看點

搭建LNAMP環境(三)- 源碼安裝Apache2.4

上一篇:搭建LNAMP環境(二)- 源碼安裝Nginx1.10

1.yum安裝編譯apache需要的包(如果已經安裝,可跳過此步驟)

yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel      

2.建立apache使用者組和使用者

groupadd apache
useradd -r -g apache -s /sbin/nologin -M apache      

3.下載下傳apache源碼包及依賴包apr和apr-util,将它們放到/usr/local/src/目錄下

源碼包下載下傳頁面:http://httpd.apache.org/download.cgi

依賴包下載下傳頁面:http://apr.apache.org/download.cgi

這裡用的是 httpd-2.4.23.tar.gz ,apr-1.5.2.tar.gz ,apr-util-1.5.4.tar.gz

apache下載下傳位址:    http://apache.fayea.com/httpd/httpd-2.4.23.tar.gz

apr下載下傳位址:         http://apache.fayea.com/apr/apr-1.5.2.tar.gz

apr-util下載下傳位址:   http://apache.fayea.com/apr/apr-util-1.5.4.tar.gz

4.進入src/目錄

cd /usr/local/src/      

5.解壓apache源碼包及依賴包

tar -zxf httpd-2.4.23.tar.gz
tar -zxf apr-1.5.2.tar.gz
tar -zxf apr-util-1.5.4.tar.gz      

6.編譯安裝apr

cd /usr/local/src/apr-1.5.2

./configure --prefix=/usr/local/apr

make && make install      

注:如果./configure時出現報錯:

error info:rm: cannot remove `libtoolT': No such file or directory

解決方法:

打開configure檔案

vim configure

找到

 $RM "$cfgfile"

改為

 $RM -f "$cfgfile"

儲存後再次執行即可

7.編譯安裝apr-util

cd /usr/local/src/apr-util-1.5.4

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

make && make install      

8.編譯安裝apache(配置參數:http://httpd.apache.org/docs/2.4/programs/configure.html)

cd /usr/local/src/httpd-2.4.23

./configure \
--prefix=/usr/local/apache \
--sysconfdir=/usr/local/apache/conf \
--enable-so \
--enable-cgi \
--enable-deflate \
--enable-rewrite \
--enable-modules=most \
--enable-mpms-shared=all \
--enable-ssl \
--with-ssl \
--with-z \
--with-pcre \
--with-zlib \
--with-mpm=event \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/

make && make install      

9.修改apache配置檔案httpd.conf

vim /usr/local/apache/conf/httpd.conf      

10.修改為下面内容,儲存退出

#如果前面已經安裝了nginx,為防止端口沖突,這裡改為其他端口
Listen 8088

#使用者組和使用者改為apache
User apache
Group apache

#ServerName www.example.com:80
ServerName 127.0.0.1      

11.修改apache目錄權限

chown -R apache:apache /usr/local/apache      

12.将apache服務腳本加入到init.d/目錄

cp /usr/local/apache/bin/apachectl /etc/init.d/httpd      

13.修改腳本httpd

vim /etc/init.d/httpd      

14.在首行 #!/bin/sh 下面加入兩行:

# chkconfig: 345 85 15
# description: Activates/Deactivates Apache Web Server      

第一行3個數字參數意義分别為:哪些Linux級别需要啟動httpd(3,4,5);啟動序号(85);關閉序号(15)

15.将apache加入系統服務

chkconfig --add httpd      

16.修改服務的預設啟動等級

chkconfig httpd on      

17.啟動apache

service httpd start      

通路URL,如:http://192.168.8.9:8088/

頁面顯示正常,則配置成功

Apache安裝完畢!

下一篇:搭建LNAMP環境(四)- 源碼安裝PHP7

  • 作者:成九
  • 出處:https://luyucheng.cnblogs.com
  • 若無特别說明均為原創作品,如需轉載請注明原文連結

如果您覺得本文對您的學習有所幫助,可通過支付寶來打賞部落客,增加部落客的寫作動力

繼續閱讀