CentOS 6.8 搭建LNAMP環境(三)- 源碼安裝Apache2.4.28

一、yum安裝編譯apache須要的包

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

 二、下載apache源碼包及依賴包apr和apr-util,將它們放到/usr/local/src/目錄下

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

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

三、進入/usr/local/src/目錄,解壓apache源碼包及依賴包

cd /usr/local/src/apache

tar -zxvf httpd-2.4.28.tar.gz vim

tar -zxvf apr-1.6.2.tar.gz spa

tar -zxvf apr-util-1.6.0.tar.gz htm

四、編譯安裝apr

cd /usr/local/src/apr-1.6.2ip

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

make && make installrem

注:若是./configure時出現報錯: error info:rm: cannot remove `libtoolT': No such file or directory

 解決方法:

打開configure文件

vim configure

找到

$RM "$cfgfile"

改成

$RM -f "$cfgfile"

保存後再次執行便可

五、編譯安裝apr-util

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

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

make && make install

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

cd /usr/local/src/httpd-2.4.28

./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/ --with-included-apr

make && make install

注:若是./configure時出現報錯:configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

解決方法:

cp -rf /usr/local/src/apr-1.6.2 /usr/local/src/httpd-2.4.28/srclib/apr

cp -rf /usr/local/src/apr-util-1.6.0 /usr/local/src/httpd-2.4.28/srclib/apr-util

再次執行便可。

七、修改apache配置文件httpd.conf

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

#前面已經安裝了nginx,爲防止端口衝突,這裏改成其餘端口

找到:    Listen 80

改成:    Listen 8080

找到:    #ServerName www.example.com:80

改成:    ServerName 127.0.0.1:8080

找到:    DocumentRoot "/usr/local/apache/htdocs"     #默認web根目錄 

改成:    DocumentRoot "/var/www/html"

找到:    <Directory "/usr/local/apache/htdocs">

改成:    <Directory "/var/www/html">

 

八、將apache服務腳本加入到init.d/目錄

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

九、修改腳本httpd

vim /etc/init.d/httpd

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

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

十、將apache加入系統服務

chkconfig --add httpd

十一、修改服務的默認啓動等級(開機自啓)

chkconfig httpd on

十二、啓動apache

service httpd start

訪問URL,如:http://192.168.198.119:8080/

注:若不能訪問,則關閉防火牆

service iptables stop

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

Apache安裝完畢!

相關文章
相關標籤/搜索