下面是linux下安裝apache的完整代碼,系統是redhat5.5
下載httpd-2.2.6.tar.bz2 把httpd-2.2.6.tar.bz2放到/soft 下
[root@localhost ~]#cd /soft
[root@localhost soft]#tar jxvf httpd-2.2.6.tar.bz2 //解壓apache的壓縮包
[root@localhost soft]#cd httpd-2.2.6 //定位到httpd-2.2.6 文件夾下
[root@localhost httpd-2.2.6]#ls //查看顯示httpd-2.2.6 文件夾下內容
[root@localhost httpd-2.2.6]#./configure --help | more //查看安裝apache配置參數
[root@localhost httpd-2.2.6]#./configure --prefix=/usr/local/apache --enable-so // 配置apache路徑
[root@localhost httpd-2.2.6]#make //編譯apache
[root@localhost httpd-2.2.6]#make install //安裝apache
[root@localhost httpd-2.2.6]#cd /usr/local/apache //進入apache的目錄
[root@localhost apache]# cd conf/
[root@localhost conf]#cp -a httpd.conf httpd.conf- //備份apache配置文件
[root@localhost conf]#chkconfig --list httpd //查看httpd服務是否已存在
[root@localhost conf]#chkconfig httpd off //關閉系統自帶了httpd的服務,如果存在httpd服務
[root@localhost conf]#service httpd status //查看自帶httpd服務狀態
[root@localhost conf]#/usr/local/apache/bin/apachectl -k start //linux啓動apache命令
[root@localhost conf]#netstat -an | grep :80 //查看linux80端口是否開啓
[root@localhost conf]#ps -aux | grep httpd //linux下查看apache進程
[root@localhost conf]#cd ../..
[root@localhost local]#cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/apache //拷貝apache啓動腳本
[root@localhost local]#vi /etc/rc.d/init.d/apache // 這裏是編輯apache啓動腳本
在開頭的#!/bin/sh 下面加上
#chkconfig: 2345 85 15
[root@localhost local]#chkconfig --add apache //添加apache服務
在這一步的時候會出現chkconfig --add apache apache 服務不支持 chkconfig
可以改爲chkconfig --add httpd,後面可相應把apache改爲httpd,文章最後面有另一種方法。
[root@localhost local]#chkconfig --list apache //列出apache服務
[root@localhost local]#service apache stop //停止apache服務
[root@localhost local]#netstat -an | grep :80 //查看linux的80端口是否關閉
[root@localhost local]#ps -aux | grep httpd //查看是否存在httpd服務,若果之前自帶httpd服務啓動的話會導致新添加的apache服務啓動失敗
[root@localhost local]#service apache start //啓動apache服務
打開你的服務器ip地址,看看是否出現了tomcat的默認首頁,如果出現的話,那麼恭喜你
linux下安裝apache已經成功了
Apache無法自動啓動,
1、將apachectl文件拷貝到/etc/rc.d/init.d 中,然後在/etc/rc.d/rc5.d/下加入鏈接即可。
命令如下:
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd //如果有其他的版本的Apache存在,也可以直接覆蓋掉
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc5.d/S85httpd //建立鏈接(85的意義後面介紹)
此時Apache就可以自動啓動了。
2、 運行chkconfig --list,發現沒有linux服務列表中httpd,通過chkconfig --add httpd來添加,但是提示:httpd服務不支持 chkconfig。需要編輯/etc/rc.d/init.d/httpd,添加以下注釋信息:
# chkconfig: 345 85 15
# description: Activates/Deactivates Apache Web Server
第一行3個數字參數意義分別爲:哪些Linux級別需要啓動httpd(3,4,5);啓動序號(85);關閉序號(15)。
保存後執行:chkconfig --add httpd,成功添加。
在rc3.d、rc4.d、rc5.d路徑中會出現S85httpd的鏈接文件,其他運行級別路徑中會出現K61httpd的鏈接文件。
3、運行chkconfig --list httpd