linux系統下源碼安裝Apache2.4
下載Apache及相關依賴包(百度雲盤:http::/pan.baidu.com/s/1bnL31c7)
Apache2.4版本開始不自帶apr庫,所以需要下載相應的庫文件
1.apr(Apache依賴包) http://irrors.hust.edu.cn/apache/apr
2.apr-util(Apache依賴包) http://irrors.hust.edu.cn/apache/apr
3.pcre(Apache依賴包) http://sourceforge.net/projects/pcre/files/pcre/
4.Apache http://archive.apache.org/dist/httpd/
安裝apr,apr-util以及pcre依賴包
開始安裝依賴包,注意:需要將解壓包放到apache軟件解壓後的srclib目錄下面也就是這裏的/soft/httpd-2.4.16/srclib/
解壓Apache及相關依賴包
[root@localhost soft]#tar -zxvf httpd-2.4.16.tar.gz
[root@localhost soft]#tar -zxvf apr-1.5.2.tar.gz
[root@localhost soft]#tar -zxvf apr-util-1.5.4.tar.g
[root@localhost soft]#tar -zxvf pcre-8.37.tar.gz
將相關依賴包放入/soft/httpd-2.4.16/srclib/中
[root@localhost soft]#mv apr-1.5.2 /httpd-2.4.16/srclib/apr
[root@localhost soft]#mv apr-util /httpd-2.4.16/srclib/apr-util
安裝apr
[root@localhost soft]# cd /soft/httpd-2.4.16/srclib/
[root@localhost srclib]# cd apr 在目錄apr下進入configure配置文件將$RM "cfgfile"這一行用#註銷
[root@localhost apr]# ./configure --prefix=/usr/local/apr
[root@localhost apr]# make && make install
安裝apr-util
[root@localhost srclib]# cd apr-util
[root@localhost apr-util]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
[root@localhost apr-util]# make && make install
安裝pcre
[root@localhost srclib]# tar -zxvf pcre-8.37.tar.gz
[root@localhost srclib]# mv pcre-8.37 pcre
[root@localhost pcre-8.37]# ./configure --prefix=/usr/local/pcre
[root@localhost pcre-8.37]# make && make install
安裝Apache
[root@localhost soft]# cd httpd-2.4.16
[root@localhost httpd-2.4.16]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --with-z=/usr/local/zlib/ --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
[root@localhost httpd-2.4.16]#make && make install
Apache安裝詳細說明
[root@localhost httpd-2.4.16]# ./configure \ 執行當前目錄下軟件自帶的配置命令
> --prefix=/usr/local/apache2 \ 指定Apache軟件安裝的位置
> --sysconfdir=/etc/httpd \ 指定Apache服務器配置文件存放位置
> --with-z=/usr/local/zlib/ \ 指定zlib庫文件的位置
> --enable-so \ 以動態共享對象(DSO)編譯
> --enable-deflate=shared \ 縮小傳輸編碼的支持
> --enable-expires=shared \ 期滿頭控制
> --enable-rewrite=shared \ 基於規則的URL操控
> --enable-static-support \ 建立一個靜態鏈接版本的支持
>--with-apr=/usr/local/apr \ 加入apr依賴包安裝路徑
>--with-apr-util=/usr/local/apr-util \ 加入apr-util依賴包安裝路徑
>--with-pcre=/usr/local/pcre 加入pcre依賴包安裝路徑
啓動apache服務
進入/etc/httpd/httpd.conf配置文件,在任意行插入一行內容
ServerName localhost:80
[root@localhost httpd]# /usr/local/apache2/bin/apachectl start
httpd (pid 55493) already running
註冊爲服務
[root@end ~]# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
[root@end ~]# service httpd start
httpd (pid 45005) already running
查看Apache服務端口情況
[root@localhost httpd]# netstat -na |grep 80
tcp 0 0 :::80 :::* LISTEN
加入到chkconfig
進入/etc/init.d/httpd,在任意行插入加入兩行內容
# chkconfig: 345 61 61
# description:Apache httpd
[root@end ~]# chkconfig --add httpd
[root@end ~]# chkconfig httpd on
關閉iptables
[root@localhost httpd]# iptables -F 清空iptables防火牆策略
[root@localhost httpd]# service iptables stop 關閉防火牆
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@localhost httpd]# chkconfig iptables off 重啓後防火牆依舊處於關閉狀態
關閉selinux
兩種方法
1.使用命令setenforce 0 系統重啓即失效(不需要重啓)
2.編輯配置文件/etc/sysconfig/selinux 將SELINUX=enforcing改爲disabled狀態( 須重啓生效)
[root@localhost httpd]# setenforce 0 臨時將selinux改爲Permission狀態,重啓系統後失效
[root@localhost httpd]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled 將selinux改爲disabled狀態,需要重啓系統才能生效
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
測試Apache服務
最後打開網頁,輸入網址http://ip即可查看網頁內容
網頁顯示It works!就說明apache安裝成功了
那麼至此Apache的源碼安裝到此就結束了!