標籤:
安裝Apache前準備:
一、檢查該環境中是否已經存在httpd服務的設定檔,預設儲存路徑:/etc/httpd/httpd.conf(這是centos預裝的Apache的一個ent版本,一般我們安裝原始碼版的Apache)。如果已經存在/etc/httpd/httpd.conf,請先卸載或者關閉centos系統內建的web服務,執行命令:chkconfig httpd off,再或者把centos內建的httpd服務的80連接埠改為其他連接埠,只要不與我們安裝的Apache服務的連接埠衝突就可以啦。
停止並卸載Linux系統內建的httpd服務:
1、service httpd stop
2、ps -ef | grep httpd
3、kill -9 pid號(逐個刪除)
4、rpm -qa |grep httpd
5、rpm -e httpd軟體包
[[email protected] bin]# find / -name httpd.conf
[[email protected] bin]#
二, 下載Apache安裝包 httpd-2.4.10.tar.gz ,:http://httpd.apache.org/
在安裝Apache時,我分別針對不同版本進行了安裝,在編譯時間是不同的,configure後跟的參數不同。
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre #(除了指定Apache的安裝目錄外,還要安裝apr、apr-util、pcre,並指定參數)
make
make install
在編譯Apache(在安裝httpd-2.4.10時遇到的問題)時分別出現了apr not found、APR-util not found、pcre-config for libpcre not found的問題,下面就httpd-2.4.10的這些問題解決來實際操作一把。
1, 解決apr not found問題
[[email protected] bin]# tar -zxf apr-1.4.5.tar.gz
[[email protected] apr-1.4.5]# ./configure --prefix=/usr/local/apr
[[email protected] apr-1.4.5]# make
[[email protected] apr-1.4.5]# make install
2.解決APR-util not found問題
[[email protected] bin]# tar -zxf apr-util-1.3.12.tar.gz
[[email protected] apr-util-1.3.12]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
[[email protected] apr-util-1.3.12]# make
[[email protected] apr-util-1.3.12]# make install
3、解決pcre-config for libpcre not found問題
[[email protected] ~]# unzip pcre-8.31.zip
[[email protected] ~]# cd pcre-8.31
[[email protected] pcre-8.31]# ./configure --prefix=/usr/local/pcre
[[email protected] pcre-8.31]#
make[[email protected] pcre-8.31]# make install
apache服務自啟動設定
[email protected]#cp /usr/local/apahe/bin/apachectl /etc/rc.d/init.d/httpd
[email protected]#vim /etc/rc.d/init.d/httpd
在httpd中加入
#chkconfig: 35 85 15
#description: apache
儲存退出。
[email protected]# chkconfig --add httpd
[email protected]# chkconfig httpd on
查看一下是否添加成功:
chkconfig --list httpd
測試:
[email protected]# service httpd start
如報 AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName‘ directive globally to suppress this message
Apache的設定檔則是conf目錄下的httpd.conf檔案,將其開啟:
找到ServerName(約213行),將其設定為localhost:80,並將前面的井號刪除
測試:
[[email protected] ~]# curl http://localhost
<html><body><h1>It works!</h1></body></html>
linux 安裝 apache