這是我首次嘗試的經驗(Centos7最小化安裝),走了不少坑,藉此記錄一下,但願朋友們少走一些彎路;
我是經過下載源碼安裝的,全部的下載文件爲*.tar.bz2壓縮包(不一樣壓縮方式,解壓方式不一樣,我就下載同一種了);linux
一次性把文件下載好,其中包括:
apr-1.5.2
apr-util-1.5.4
pcre-8.37(若是沒記錯的話,這個不要下載最新版;記錯的話,以上三個有一個不要下載最新版——我好不負責)
httpd-2.4.18c++
# gcc -v
若是沒有的話,安裝文件時會報錯,能夠根據提示安裝相應文件;
我是經過yum install安裝的gcc 、c++apache
[root@root]# yum install gcc -y [root@root]# yum install gcc-c++ -y
把第一步下載好的源碼包解壓:服務器
tar -jxvf DirName.tar.bz2
固然,若是你沒有解壓工具,請經過:網絡
yum search bzip2查找安裝解壓工具;
若是直接安裝Apache的話(我就不直接安裝),它有可能會報錯(我都是必定會報錯):curl
checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking target system type... i686-pc-linux-gnu configure: configure: Configuring Apache Portable Runtime library... configure: checking for APR... no configure: error: APR not found. Please read the documentation.
這時候第一步下載的文件就用的上了; 安裝順序apr -> apr-util ,固然pcre能夠亂入(順序不重要); 安裝過程,配置 -> 編譯 -> 安裝 三部曲; 主要說配置: 進入解壓後的apr文件包: [root@root]# ./configure --prefix=/usr/local/apr/(這裏配置的是安裝路徑) # make # make intall 進入解壓後的apr-util文件包: [root@root]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config(配置apr-util安裝路徑,並關聯apr文件——確保路徑正確) # make # make intall 進入解壓後的pcre文件包: [root@root]# ./configure --prefix=/usr/local/pcre(配置安裝路徑) # make # make intall
關聯文件安裝結束後就是主菜了:tcp
進入解壓後的httpd文件包: [root@root]# ./configure --prefix=/usr/local/apache/ \ --sysconfdir=/etc/httpd \ //指定Apache服務器的配置文件存放位置 --with-apr=/usr/local/apr \ --with-apr-util=/usr/local/apr-util/ \ --with-pcre=/usr/local/pcre/ \ --enable-so \ //以動態共享對象(DSO)編譯---記得要加,不然之後手動修改配置文件加載新的模塊,好比,不配置的話,安裝好PHP後,要手動修改conf來loadmodule…… --enable-deflate=shared \ //縮小傳輸編碼的支持 --enable-expires=shared \ //期滿頭控制 --enable-rewrite=shared \ //基於規則的URL操控 --enable-static-support //創建一個靜態連接版本的支持 # make # make intall
進入Apache的目錄/etc/httd/工具
修改httpd.conf配置文件(Apache2.4與2.2配置不一樣) Require all denied(禁止外部訪問) Require all granted(容許外部訪問)
進入Apache的安裝目錄/usr/local/apache/bin(若是你沒自定義的話):ui
./apachectl start #啓動服務 ./apachectl stop #關閉服務 ./apachectl restart #重啓服務
我用的Centos7不會提醒服務已啓動,因此,我通常一個命令運行兩次,第二次它會報告服務已啓動/已關閉;this
啓動就ok了?我曾經是這樣認爲的——但是,坑還在繼續……
外網/局域網訪問不了:
排查1: 服務器/虛擬機自身網絡是否正常,能夠經過ping http://www.baidu.com度娘地址試試; 排查2: 服務是否啓動,佔用80端口的是否爲http服務: netstat -ntpl #查看端口監聽(個人是,因此,我就沒有了關閉其它進程的經驗) 若是你不必定非要80端口的話,能夠修改/usr/local/apache/conf/httpd.conf監聽端口; 排查3: You don't have permission to access / on this server 沒有權限,解決方案: chmod o+x /usr/ chmod o+x /usr/local/ chmod o+x /usr/local/apache/ chmod o+x /usr/local/apache/htdocs(每一級目錄都要執行) 以上問題能夠經過curl http://127.0.0.1在服務器/虛擬機上檢驗本地是否能夠訪問; 排查4: 防火牆設置——Centos7默認使用firewalld代替iptables(網上多數是iptables的設置解決方案,**好吧!發現Centos7有的小版本還在用iptables**因此,只能嘗試兩個命令,存在的就是用的該防火牆) systemctl start firewalld #啓動 systemctl status firewalld #查看狀態 systemctl disable firewalld #中止 systemctl stop firewalld #禁用(能夠直接禁用防火牆,也能夠添加80端口到例外) 查看活動區域狀態: # firewall-cmd --get-active-zones(firewall-cmd是一個合成詞) 返回: [root@localhost bin]# firewall-cmd --get-active-zones **public** interfaces: eno16777736 重要的是**public**、dmz,或者其它。根據這個值的不一樣,添加端口的語句也不一樣; 加入一個端口到dmz區域: # firewall-cmd --zone=dmz --add-port=80/tcp 加入一個端口到public區域: # firewall-cmd --zone=public --add-port=80/tcp 永久生效再加上 --permanent 而後reload防火牆 # firewall-cmd --zone=dmz --add-port=80/tcp --permanent 或者 # firewall-cmd --zone=public --add-port=80/tcp --permanent # firewall-cmd --complete-reload 查看全部活動的端口: # firewall-cmd --zone=dmz --list-ports 或者 # firewall-cmd --zone=public --list-ports
因爲我進行了不少步操做來解決外部訪問的問題,因此,最終僅僅經過以上調試方法可否獲得外部訪問的結果,不敢保證;
如不行: 檢查一下selinux設置(其它問題只能自行百度了)……